Giter VIP home page Giter VIP logo

flask-s3-dropzone's Introduction

This is a Flask app that demonstrates how to upload file(s) directly to S3 using pre-signed post. The frontend is powered by Dropzone.js that enables features like drag-and-drop, queued upload, etc. If you want to implement your uploader differently, please check the official Dropzone.js documentation and change the code accordingly. The following is a sequence diagram that shows how requests bounce between different entities when a file is uploaded. The primary advantages of this design are twofold.

  • Upload can scale basically indefinitely, unlimited storage space and high concurrency support on S3.
  • No need to expose AWS credentials to clients (browser, mobile app, etc.).
┌──────┐                       ┌──────┐          ┌──┐
│Client│                       │Server│          │S3│
└──┬───┘                       └──┬───┘          └┬─┘
   │   POST /get-presigned-post   │               │  
   │ ─────────────────────────────>               │  
   │                              │               │  
   │ RETURN S3 signed post in JSON│               │  
   │ <─────────────────────────────               │  
   │                              │               │  
   │     POST file to S3 URL with signed post     │  
   │ ─────────────────────────────────────────────>  
   │                              │               │  
   │            RETURN 200 confirmation           │  
   │ <─────────────────────────────────────────────  
┌──┴───┐                       ┌──┴───┐          ┌┴─┐
│Client│                       │Server│          │S3│
└──────┘                       └──────┘          └──┘

Prerequisite

  • Make sure the server running Flask app has sufficient IAM permissions to generate S3 pre-signed post.
  • Make sure the destination bucket allows Cross-Origin Resource Sharing (CORS).
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>HEAD</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

Example

Success

success

Error

error

Reference

flask-s3-dropzone's People

Contributors

jinmingda avatar

Stargazers

 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.