Utilities for private/protected file storage.
This field is a dropin replacement for FileField, but the files require you to be logged in.
Add to urls:
url(r'^private-files/', include('alpaca.private_storage.urls')),
Use field:
def check_file_permission(user, obj):
if user.is_authenticated and obj.user == user
class MyModel(Model):
my_file = S3PrivateFileField(permission_func=check_file_permission)
Reference the file url like normal:
{{ my_object.my_file.url }}
If you need the original S3 url for some reason, access it with _private_url
:
{{ my_object.my_file._private_url }}
However, if you do that, that is kind of missing the point of the private file.
Note: for this to work, the S3 bucket needs to be using Access Control List (ACL) and NOT a Bucket Policy. Usually, you can just delete any bucket policy there, and the ACL will be used.