1. Waldemar Kornewald
  2. django-filetransfers


Waldemar Kornewald  committed 91734ba

added delegate backend which delegates uploads to other backends based on private=True or False. useful for e.g. letting Blobstore handle private uploads and letting S3 handle public uploads

  • Participants
  • Parent commits 9a6c60e
  • Branches default

Comments (0)

Files changed (3)

File filetransfers/backends/default.py

View file
  • Ignore whitespace
 def prepare_upload(request, url, **kwargs):
     """Directly uploads to the given URL"""
-    return url
+    return url, {}
 def serve_file(request, file, save_as, content_type, **kwargs):

File filetransfers/backends/delegate.py

View file
  • Ignore whitespace
+from django.conf import settings
+from filetransfers.api import prepare_upload as delegate
+def prepare_upload(*args, **kwargs):
+    """Delegates uploads to other backends based on private=False or True"""
+    if kwargs['private']:
+        kwargs['backend'] = settings.DELEGATE_PRIVATE_UPLOADS
+    else:
+        kwargs['backend'] = settings.DELEGATE_PUBLIC_UPLOADS
+    return delegate(*args, **kwargs)

File filetransfers/backends/url.py

View file
  • Ignore whitespace
 from django.http import HttpResponseRedirect
 from django.utils.encoding import smart_str
-def serve_file(request, file, save_as, content_type, **kwargs):
+def serve_file(request, file, **kwargs):
     """Serves files by redirecting to file.url (e.g., useful for Amazon S3)"""
     return HttpResponseRedirect(smart_str(file.url))