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

Comments (0)

Files changed (3)


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


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


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