Commits

Anonymous 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

Comments (0)

Files changed (3)

filetransfers/backends/default.py

 
 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):
     """

filetransfers/backends/delegate.py

+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)

filetransfers/backends/url.py

 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))