Upload file in Flask with Dropzone.js.
Project description
Flask-Dropzone
================
Upload file in Flask with [Dropzone.js](http://www.dropzonejs.com/).
Installation
------------
pip install flask-dropzone
Quick Start
-----------
Step 1: Initialize the extension:
from flask_dropzone import Dropzone
dropzone = Dropzone(app)
This extension also supports the [Flask application factory pattern](http://flask.pocoo.org/docs/latest/patterns/appfactories/) by allowing you to create a Dropzone object and then separately initialize it for an app:
dropzone = Dropzone()
def create_app(config):
app = Flask(__name__)
app.config.from_object(config)
dropzone.init_app(app)
...
return app
Step 2: In your `<head>` section of your base template add the following code:
{{ dropzone.include_dropzone() }}
Step 3: Creating a form element with the class `dropzone` and id `myDropzone` in the place where you want to upload file:
<form action="{{ url_for('upload_file') }}" class="dropzone" id="myDropzone" method="POST" enctype="multipart/form-data">
</form>
Also to edit the action to your upload address.
Configuration
-------------
The supported list of config options is shown below:
| Name | Default Value | Info |
| ------------------------ | ------------- | ---- |
| `DROPZONE_SERVE_LOCAL` | False | default to use CDN |
| `DROPZONE_MAX_FILE_SIZE` | 2 | unit: MB |
| `DROPZONE_INPUT_NAME` | `file` | `<input type="file" name="file">` |
| `DROPZONE_ALLOWED_FILE_CUSTOM` | False | see detail below |
| `DROPZONE_ALLOWED_FILE_TYPE` | `allowed_file_type['default']` | see detail below |
| `DROPZONE_MAX_FILES` | 'null' | the max files user can upload once |
| `DROPZONE_DEFAULT_MESSAGE` | "Drop files here to upload" | message displayed on drop area |
| `DROPZONE_INVALID_FILE_TYPE` | "You can't upload files of this type." | error message |
| `DROPZONE_FILE_TOO_BIG` | "File is too big {{filesize}}. Max filesize: {{maxFilesize}}MiB." | error message |
| `DROPZONE_SERVER_ERROR` | "Server error: {{statusCode}}" | error message |
| `DROPZONE_BROWSER_UNSUPPORTED` | "Your browser does not support drag'n'drop file uploads." | error message |
| `DROPZONE_MAX_FILE_EXCEED` | "Your can't upload any more files." | error message |
You can use these file type:
allowed_file_type = {
'default': 'image/*, audio/*, video/*, text/*, application/*',
'image': 'image/*',
'audio': 'audio/*',
'video': 'video/*',
'text': 'text/*',
'app': 'application/*'
}
If you want to set the allowed file type by yourself, you need to set
`DROPZONE_ALLOWED_FILE_CUSTOM` to `True`, then add mime type or file extensions to
`DROPZONE_ALLOWED_FILE_TYPE`, such as:
app.config[`DROPZONE_ALLOWED_FILE_TYPE`] = 'image/*, .pdf, .txt'
Consult the [dropzone.js documentation](http://dropzonejs.com/) for details on these options.
ChangeLog
=========
1.1
----
* Add more configuration options.
* Support local resource serve.
* Add basic documentation.
1.0
----
* Init release.
================
Upload file in Flask with [Dropzone.js](http://www.dropzonejs.com/).
Installation
------------
pip install flask-dropzone
Quick Start
-----------
Step 1: Initialize the extension:
from flask_dropzone import Dropzone
dropzone = Dropzone(app)
This extension also supports the [Flask application factory pattern](http://flask.pocoo.org/docs/latest/patterns/appfactories/) by allowing you to create a Dropzone object and then separately initialize it for an app:
dropzone = Dropzone()
def create_app(config):
app = Flask(__name__)
app.config.from_object(config)
dropzone.init_app(app)
...
return app
Step 2: In your `<head>` section of your base template add the following code:
{{ dropzone.include_dropzone() }}
Step 3: Creating a form element with the class `dropzone` and id `myDropzone` in the place where you want to upload file:
<form action="{{ url_for('upload_file') }}" class="dropzone" id="myDropzone" method="POST" enctype="multipart/form-data">
</form>
Also to edit the action to your upload address.
Configuration
-------------
The supported list of config options is shown below:
| Name | Default Value | Info |
| ------------------------ | ------------- | ---- |
| `DROPZONE_SERVE_LOCAL` | False | default to use CDN |
| `DROPZONE_MAX_FILE_SIZE` | 2 | unit: MB |
| `DROPZONE_INPUT_NAME` | `file` | `<input type="file" name="file">` |
| `DROPZONE_ALLOWED_FILE_CUSTOM` | False | see detail below |
| `DROPZONE_ALLOWED_FILE_TYPE` | `allowed_file_type['default']` | see detail below |
| `DROPZONE_MAX_FILES` | 'null' | the max files user can upload once |
| `DROPZONE_DEFAULT_MESSAGE` | "Drop files here to upload" | message displayed on drop area |
| `DROPZONE_INVALID_FILE_TYPE` | "You can't upload files of this type." | error message |
| `DROPZONE_FILE_TOO_BIG` | "File is too big {{filesize}}. Max filesize: {{maxFilesize}}MiB." | error message |
| `DROPZONE_SERVER_ERROR` | "Server error: {{statusCode}}" | error message |
| `DROPZONE_BROWSER_UNSUPPORTED` | "Your browser does not support drag'n'drop file uploads." | error message |
| `DROPZONE_MAX_FILE_EXCEED` | "Your can't upload any more files." | error message |
You can use these file type:
allowed_file_type = {
'default': 'image/*, audio/*, video/*, text/*, application/*',
'image': 'image/*',
'audio': 'audio/*',
'video': 'video/*',
'text': 'text/*',
'app': 'application/*'
}
If you want to set the allowed file type by yourself, you need to set
`DROPZONE_ALLOWED_FILE_CUSTOM` to `True`, then add mime type or file extensions to
`DROPZONE_ALLOWED_FILE_TYPE`, such as:
app.config[`DROPZONE_ALLOWED_FILE_TYPE`] = 'image/*, .pdf, .txt'
Consult the [dropzone.js documentation](http://dropzonejs.com/) for details on these options.
ChangeLog
=========
1.1
----
* Add more configuration options.
* Support local resource serve.
* Add basic documentation.
1.0
----
* Init release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Flask-Dropzone-1.2.zip
(7.3 kB
view details)
File details
Details for the file Flask-Dropzone-1.2.zip
.
File metadata
- Download URL: Flask-Dropzone-1.2.zip
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe3717c7f11b6433ed1743791db62deeecfe295711d1b60ddc1b30c8c53904ee |
|
MD5 | 89f75a9d097847081c33603ec4637823 |
|
BLAKE2b-256 | 913dc6b6db2de7e0e0388f6679bfc72946e494dcb294692621805a579bd11e52 |