skip to navigation
skip to content

django-s3direct 0.3.11

Add direct uploads to S3 functionality with a progress bar to file input fields.


Upload files direct to S3 from Django

[![Build Status](](
[![PyPi Version](](
[![PyPi Downloads](](

Add direct uploads to AWS S3 functionality with a progress bar to file input fields.


## Support
Python 2/3
Chrome / Safari / Firefox / IE10+

For older browser support use version 0.1.10.

## Installation

Install with Pip:

```pip install django-s3direct```

## S3 Setup

Setup a CORS policy on your S3 bucket.


## Django Setup



# AWS keys

# The region of your bucket, more info:
S3DIRECT_REGION = 'us-east-1'

# Destinations in the following format:
# {destination_key: (path_or_function, auth_test, [allowed_mime_types], permissions, custom_bucket)}
# 'destination_key' is the key to use for the 'dest' attribute on your widget or model field
# Allow anybody to upload any MIME type
'misc': ('uploads/misc',),

# Allow staff users to upload any MIME type
'files': ('uploads/files', lambda u: u.is_staff,),

# Allow anybody to upload jpeg's and png's.
'imgs': ('uploads/imgs', lambda u: True, ['image/jpeg', 'image/png'],),

# Allow authenticated users to upload mp4's
'vids': ('uploads/vids', lambda u: u.is_authenticated(), ['video/mp4'],),

# Allow anybody to upload any MIME type with a custom name function, eg:
'custom_filename': (lambda original_filename: 'images/unique.jpg',),

# Specify a non-default bucket for PDFs
'pdfs': ('/', lambda u: True, ['application/pdf'], None, 'pdf-bucket',),

# Allow logged in users to upload any type of file and give it a private acl:
'private': (
lambda u: u.is_authenticated(),

# Allow authenticated users to upload with cache-control for a month and content-disposition set to attachment
'cached': (
lambda u: u.is_authenticated(),


urlpatterns = patterns('',
url(r'^s3direct/', include('s3direct.urls')),

Run ```python collectstatic``` if required.

## Use in Django admin only


from django.db import models
from s3direct.fields import S3DirectField

class Example(models.Model):
video = S3DirectField(dest='destination_key_from_settings')

## Use the widget in a custom form


from django import forms
from s3direct.widgets import S3DirectWidget

class S3DirectUploadForm(forms.Form):
images = forms.URLField(widget=S3DirectWidget(dest='destination_key_from_settings'))


from django.views.generic import FormView
from .forms import S3DirectUploadForm

class MyView(FormView):
template_name = 'form.html'
form_class = S3DirectUploadForm

### templates/form.html

<meta charset="utf-8">
{{ }}
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}

## Examples
Examples of both approaches can be found in the examples folder. To run them:
$ git clone
$ cd django-s3direct
$ python install
$ cd example

# Add your AWS keys to

$ python syncdb
$ python runserver

Visit ```http://localhost:5000/admin``` to view the admin widget and ```http://localhost:5000/form``` to view the custom form widget.  
File Type Py Version Uploaded on Size
django-s3direct-0.3.11.tar.gz (md5) Source 2015-05-24 14KB
  • Downloads (All Versions):
  • 57 downloads in the last day
  • 882 downloads in the last week
  • 4445 downloads in the last month