Skip to content

codingjoe/django-s3file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-s3file

A lightweight file upload input for Django and Amazon S3.

PyPi Version Build Status Code Health Test Coverage Code health GitHub license Join the chat at https://gitter.im/codingjoe/django-s3file

Features

  • Pure JavaScript (no jQuery)
  • Python 2 and 3 support
  • Auto swapping based on your environment
  • Pluggable as it returns a simple django file, just like native input
  • Easily extensible (authentication, styles)

Installation

Just install S3file using pip or easy_install.

pip install django-s3file

Don't forget to add s3file to the INSTALLED_APPS.

Usage

Simple integrations

Include s3file's URLs in your URL root.

urls.py

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

forms.py

from s3file.forms import AutoFileInput class MyModelForm(forms.ModelForm): class Meta: model = MyModel fields = ('my_file_field') widgets = { 'my_file_field': AutoFileInput }

Done! No really, that's all that needs to be done.

Setting up the CORS policy on your AWS S3 Bucket

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

Advanced usage examples

Authentication

The signing endpoint supports CSRF by default but does not require a authenticated user. This and other behavior can be easily added by inheriting from the view.

views.py

from s3file.views import S3FileView from braces.views import LoginRequiredMixin class MyS3FileView(LoginRequiredMixin, S3FileView): pass

Now don't forget to change the URLs.

urls.py

urlpatterns = patterns( ... url('^s3file/sign', MyS3FileView.as_view(), name='s3file-sign'), )

License

The MIT License (MIT)

Copyright (c) 2014 Johannes Hoppe

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A lightweight file upload input for Django and Amazon S3

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors 15