django-s3direct 0.3.7

Add direct uploads to S3 functionality with a progress bar to file input fields.
django-s3direct
===============

Upload files direct to S3 from Django
-------------------------------------

[![Build Status](https://travis-ci.org/bradleyg/django-s3direct.svg?branch=master)](https://travis-ci.org/bradleyg/django-s3direct)
[![PyPi Version](https://pypip.in/v/django-s3direct/badge.png)](https://crate.io/packages/django-s3direct)
[![PyPi Downloads](https://pypip.in/d/django-s3direct/badge.png)](https://crate.io/packages/django-s3direct)

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

![screenshot](https://raw.githubusercontent.com/bradleyg/django-s3direct/master/screenshot.png)

## 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.

```xml
<CORSConfiguration>
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
```

## Django Setup

### settings.py

```python
INSTALLED_APPS = [
    ...
    's3direct',
    ...
]

# AWS keys
AWS_SECRET_ACCESS_KEY = ''
AWS_ACCESS_KEY_ID = ''
AWS_STORAGE_BUCKET_NAME = ''

# The region of your bucket, more info:
# http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
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
S3DIRECT_DESTINATIONS = {
    # 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': (
        'uploads/vids',
        lambda u: u.is_authenticated(),
        '*',
        'private')
}
```

### urls.py

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

Run ```python manage.py collectstatic``` if required.

## Use in Django admin only

### models.py

```python
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

### forms.py

```python
from django import forms
from s3direct.widgets import S3DirectWidget

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

### views.py

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

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

### templates/form.html

```html
<html>
<head>
    <meta charset="utf-8">
    <title>s3direct</title>
    {{ form.media }}
</head>
<body>
    {{ form.as_p }}
</body>
</html>
```

## Examples
Examples of both approaches can be found in the examples folder. To run them:
```shell
$ git clone git@github.com:bradleyg/django-s3direct.git
$ cd django-s3direct
$ python setup.py install
$ cd example

# Add your AWS keys to settings.py

$ python manage.py syncdb
$ python manage.py runserver 0.0.0.0:5000
```

Visit ```http://localhost:5000/admin``` to view the admin widget and ```http://localhost:5000/form``` to view the custom form widget.

Author

Bradley Griffiths

Pip

django-s3direct==0.3.7

Classifiers

  • Programming Language :: Python :: 3.4
  • Programming Language :: Python :: 2.7
  • Operating System :: OS Independent
  • License :: OSI Approved :: MIT License
  • Intended Audience :: Developers
  • Framework :: Django
  • Environment :: Web Environment
  • Development Status :: 4 - Beta
File Type Python Version Uploaded On Downloads
django-s3direct-0.3.7.tar.gz Source Oct. 29, 2014 247
Version Release Date
0.3.7 Oct. 29, 2014
0.3.6 Oct. 23, 2014
0.3.5 Oct. 21, 2014
0.3.4 Oct. 21, 2014
0.3.3 Sept. 27, 2014
0.3.2 Sept. 10, 2014
0.3.1 Sept. 7, 2014
0.3.0 Sept. 5, 2014
0.2.8 Sept. 4, 2014
0.2.7 July 30, 2014
0.2.6 July 30, 2014
0.2.5 July 30, 2014
0.2.4 July 28, 2014
0.2.3 July 28, 2014
0.2.2 July 28, 2014
0.2.1 July 24, 2014
0.2.0 July 24, 2014
0.1.10 April 23, 2014
0.1.9 March 10, 2014
0.1.8 Feb. 17, 2014
0.1.7 Jan. 24, 2014
0.1.6 Jan. 10, 2014
0.1.5 Dec. 3, 2013
0.1.3 Dec. 3, 2013
0.1.2 Nov. 22, 2013
0.1.1 Aug. 21, 2013
0.1.0 April 16, 2013
0.0.9 April 2, 2013
0.0.8 April 2, 2013
0.0.7 March 15, 2013
0.0.6 March 15, 2013
0.0.5 March 14, 2013
0.0.4 March 14, 2013
0.0.3 March 14, 2013
0.0.2 March 14, 2013
0.0.1 March 14, 2013
Date Package Version Action
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.2.6 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.1.10 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.2.7 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.2.8 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.3.5 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.3.4 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.3.7 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.3.6 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.3.1 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.3.0 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.3.3 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.3.2 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.0.2 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.0.3 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.0.1 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.0.6 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.0.7 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.0.4 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.0.5 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.1.7 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.1.6 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.1.5 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.1.3 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.1.2 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.1.1 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.1.0 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.2.0 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.2.1 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.2.2 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.2.3 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.2.4 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.2.5 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.1.9 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.1.8 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.0.8 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct 0.0.9 Release Created
Nov. 4, 2014, 1:45 p.m. django-s3direct Package Created