Python server implementation for flow.js upload library
Project description
Copyright (c) 2018 Huw Jones
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.
Download-URL: https://github.com/huwcbjones/py-flowjs/archive/master.zip
Description: flow.js python server
=======================
Python library for handling chunk uploads (based on flow-php-server). Library contains helper methods for:
* Testing if uploaded file chunk exists.
* Validating file chunk
* Creating separate chunks folder
* Validating uploaded chunks
* Merging all chunks to a single file
The library currently only supports Tornado, but it is trivial to implement interfaces for other web servers (flask, etc).
This library is compatible with HTML5 file upload library: https://github.com/flowjs/flow.js
How to get started?
--------------
Install the pip module:
```
pip install flowjs
```
Create a new py file named `upload.py`:
```python
# Import flowjs
import uuid
import os
import flowjs
config = flowjs.Config()
request = flowjs.requests.TornadoRequest(tornado_http_request)
upload_directory = "/path/to/final/upload/directory"
upload_file_name = uuid.uuid1().hex + "_" + request.get_file_name()
upload_path = os.path.join(upload_directory, upload_file_name)
try:
result = flowjs.save(upload_path, config, request)
if result:
# file was saved to path
pass
else:
# not final chunk or invalid request
pass
except flowjs.NoContent:
# Set status to 204 No Content
# Do _not_ return any content in the response body
except flowjs.BadRequest:
# Set status to 400 Bad Request
```
Config
------
## tempDir
Temporary directory where chunks are stored (will default to your system temp dir).
Make sure that the temp path exists and is writable. All chunks will be saved in this folder.
## hashNameCallback
Function applied to the request to generate a unique identifier for the file.
Defaults to a SHA1 hash of the `flowIdentifier`
## preProcessCallback
Function applied before each chunk is merged into the resultant file.
## deleteChunksOnSave
Should the server delete the file chunks after it saves the final file.
Defaults to `True`
Other Web Servers
-----------------
To use this module with other webservers, implement the `IRequest` and `IFile` interfaces with your webserver's specific implementation details.
Contribution
------------
Your participation in development is very welcome!
Platform: any
Classifier: License :: OSI Approved :: MIT License
Classifier: Development Status :: 5 - Production/Stable
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Developers
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Software Development :: Libraries
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.
Download-URL: https://github.com/huwcbjones/py-flowjs/archive/master.zip
Description: flow.js python server
=======================
Python library for handling chunk uploads (based on flow-php-server). Library contains helper methods for:
* Testing if uploaded file chunk exists.
* Validating file chunk
* Creating separate chunks folder
* Validating uploaded chunks
* Merging all chunks to a single file
The library currently only supports Tornado, but it is trivial to implement interfaces for other web servers (flask, etc).
This library is compatible with HTML5 file upload library: https://github.com/flowjs/flow.js
How to get started?
--------------
Install the pip module:
```
pip install flowjs
```
Create a new py file named `upload.py`:
```python
# Import flowjs
import uuid
import os
import flowjs
config = flowjs.Config()
request = flowjs.requests.TornadoRequest(tornado_http_request)
upload_directory = "/path/to/final/upload/directory"
upload_file_name = uuid.uuid1().hex + "_" + request.get_file_name()
upload_path = os.path.join(upload_directory, upload_file_name)
try:
result = flowjs.save(upload_path, config, request)
if result:
# file was saved to path
pass
else:
# not final chunk or invalid request
pass
except flowjs.NoContent:
# Set status to 204 No Content
# Do _not_ return any content in the response body
except flowjs.BadRequest:
# Set status to 400 Bad Request
```
Config
------
## tempDir
Temporary directory where chunks are stored (will default to your system temp dir).
Make sure that the temp path exists and is writable. All chunks will be saved in this folder.
## hashNameCallback
Function applied to the request to generate a unique identifier for the file.
Defaults to a SHA1 hash of the `flowIdentifier`
## preProcessCallback
Function applied before each chunk is merged into the resultant file.
## deleteChunksOnSave
Should the server delete the file chunks after it saves the final file.
Defaults to `True`
Other Web Servers
-----------------
To use this module with other webservers, implement the `IRequest` and `IFile` interfaces with your webserver's specific implementation details.
Contribution
------------
Your participation in development is very welcome!
Platform: any
Classifier: License :: OSI Approved :: MIT License
Classifier: Development Status :: 5 - Production/Stable
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Developers
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Software Development :: Libraries
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
flowjs-0.1.1.tar.gz
(6.2 kB
view details)
Built Distribution
File details
Details for the file flowjs-0.1.1.tar.gz
.
File metadata
- Download URL: flowjs-0.1.1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc9d81992ed7aa2377de2c1f8e194a718f03b4e19b321864405a0b839e792da9 |
|
MD5 | 076577f177759d98a1b2ba5e99175c0b |
|
BLAKE2b-256 | e25e0cd0c5f83f9204f8de22c76a9009c3513f78932dc84732bee74a8a55ce01 |
File details
Details for the file flowjs-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: flowjs-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1816d1dbbc40f8db5b845838f7928639db719c00b70f6c1cbb4c1198b65bdf49 |
|
MD5 | c961aa2bfafa91bb60d8f92a6f51e784 |
|
BLAKE2b-256 | 1c11e4cad7e72f83e5f64454db1bc501ea5be9f5195ce01fa549ada869baddad |