Plupload S3 mixin for Django
Python JavaScript
Latest commit 27e4c64 Oct 8, 2015 @burgalon Merge pull request #1 from orthographic-pedant/spell_check/conjunction
Fix typographical error(s)
Failed to load latest commit information.


Plupload S3 mixin for Django

Use this together with Plupload to upload files into your S3


django-mediagenerator – – this can be easily altered to suit your needs
djangotoolbox – – for JSONResponse. This can be easily altered if you don’t want to install djangotoolbox
appengine-urlfetch – This was built for use in AppEngine however can be easily changed to use urllib


  1. Change your model to inherit from s3mixin.models.S3Mixin instead of django.Model
  1. Add in your in ‘urlpatterns’ array:
    url(r'^userprofile/s3policy/$', 'accounts.views.userprofile_s3policy', {}, name='s3policy' ), url(r'^skin/(?P<pk>add)/s3policy/$', 'accounts.views.skin_s3policy', {}, name='s3policy' ), url(r'^skin/(?P<pk>\d+)/add/s3policy/$', 'accounts.views.skin_s3policy', {}, name='s3policy' ),
  1. Add in your
    @login_required def skin_s3policy(request, pk): ret = s3mixin.views.s3policy(request, 'accounts/skin/%s' % ( skin = Skin() if pk=='add' else Skin.objects.get(id=pk) skin.file = settings.AWS_PREFIX + ret.filename = os.path.splitext(os.path.basename(ret.filename))[0].lower() skin.user = request.user return ret

def userprofile_s3policy(request):
ret = s3mixin.views.s3policy(request, ‘accounts/userprofile/%s’ % ( )
profile = request.user.get_profile()
profile.file = settings.AWS_PREFIX + ret.filename
return ret

Example prefix might be a blog/forum id that the user has permission to.
A simplistic prefix might be the user-id to which the file will be linked to.
You may use the GET[‘file_size’] to create a more robust logic for upload size limits.

  1. In your form, use S3FileWidget
  1. In your template, make sure to include
    <script type="text/javascript" src="{% media_url 'js/plupload/plupload.full.min.js' %}"></script> <script type="text/javascript" src="{% media_url 'plupload-s3.js' %}"></script> <script type="text/javascript"> {{ form.fields.file.widget.javascript }} </script>
  1. In your add:
    AWS_ACCESS_KEY_ID = '' AWS_SECRET_ACCESS_KEY = '' AWS_MAX_FILE_SIZE = '10MB' AWS_BUCKET = 'dev-bucket' if not on_production_server else 'prod-bucket' AWS_PREFIX = '' % (AWS_BUCKET) AWS_CLOUDFRONT = '' % AWS_BUCKET # Your CNAME for Cloudfront
  2. AWS_DNS_ROTATOR = 6 # Determines if CLOUDFRONT urls will be prefixed by, ….
  3. THUMBNAIL_SERVICE = ‘’ if on_production_server else ‘’

THUMBNAIL_SERVICE may be used in conjunction with to generate thumbnails at any size on the fly. Another suggestion is to use a proxy cache to avoid generating those thumbnails on every request –

  1. Add crossdomain.xml to your AWS_BUCKET of the sort:

Also suggested is to set a robots.txt blocking crawlers from scanning the buckets.

Finally, when you think all setup is done, run the page through a browser, make sure that the widget’s javascript is rendering, and that nothing fails on the javascript


  1. Notice that the code has resize : {width : 1920, height : 1080, quality : 90} which means that all uploaded JPG/PNG will be resized if larger than 1920×1080. This seems reasonable with our current global standards. Resizing photos disables progress reporting in Flash
  2. S3Mixin has SERVER_TYPES attribute which allows setting file types which you might want to store on the server side (to allow reading the file directly from DB and not through S3). Currently it’s set to HTML files. You might want to change this.
  3. Currently only the Flash runtime of Plupload is being used in order to keep things consistent and stable. S3 requires cross-domain upload and passing multi-part consistently in order to match the signature. Some of the runtimes are not passing the same parameters exactly as the Flash runtime and might require some tweaking in order to work.
  4. Feel free to fork and help to turn this into a pluggable app which is generic enough


You can see a working example on in the edit profile page after you’re registered