Coder Social home page Coder Social logo

django-s3upload's Introduction

s3upload

This is a simple Python/django demo of using the excellent jQuery File Upload to upload large files directly to S3 using browser uploads to S3 using HTML POST and S3 CORS. I largely followed the instruction in this Ruby example, but I thought other people may want to see the Python/django example.

To run the example on your computer, do something like the following:

git clone <repo url> /tmp/s3upload
cd /tmp/s3upload
virtualenv .venv
source .venv/bin/activate
pip install -r requirements.txt
export PROJECT_ROOT=/tmp/s3upload
export DJANGO_SECRET=<my secret>
export AWS_ACCESS_KEY_ID=<my amazon key ID>
export AWS_SECRET_ACCESS_KEY=<my amazon secret key>
export AWS_S3_BUCKET_URL=<bucket url>
python manage.py runserver

Naturally you should fill in the values in angle brackets with real values. AWS_S3_BUCKET_URL is the canonical URL of your bucket, for a bucket named foo in US East it would be https://foo.s3.amazonaws.com.

Your bucket will need to have a CORS policy set. Follow the instructions here to set a CORS policy. For real work, you'd like to have a policy confined to your origin domain and perhaps other conditions. For development, a suitable policy could be:

<CORSConfiguration>
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

This is all you need to get the example working. I think the code is very straightforward, but for further explanation on what's going on I suggest you read the Ruby example linked above.

I'm @aknin by the way, contact me if you have any questions.

django-s3upload's People

Contributors

yaniv-aknin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.