tus
Project description
tus python integration
This package aims to be a robust implementation of the tus resumable upload standard, tus.io.
Integrations include an api to handle WebOb requests and Zope2 requests. Additionally, you can run this server as a wsgi filter.
The package aims to be everything you need to integrate the TUS protocol into your python web applications.
Options
- tmp_file_dir
directory to store temporary files
- send_file
by default, it’ll only send the filename in the request body, not an actual file upload
- upload_valid_duration
how long before you cleanup old uploads in seconds
- upload_path
only used for WSGI filter
Basics
POST to url, response 201 with location of temp file upload url. The upload url is a combination of the base url + the unique id of the in progress file upload. Example: /upload/432jjdsfjsd78387
PATCH to temp file upload url responded to in previous POST. These can be chunks of the entire file.
Resume
HEAD to issued temp file upload url to give current size of uploaded
Integration
WebOb compatible applications
A simple Webob request adapter is provided to work with the API. This code assume it will be handling all upload related requests–meaning:
from tus import Tus, WebobAdapter adapter = WebobAdapter(req) options = { 'tmp_file_dir': '/tmp' } tus = Tus(adapter, **options) if tus.valid: tus.handle() if tus.upload_finished: fipath = tus.get_filepath() # do something here tus.cleanup_file() else: return adapter.resp
Zope2 or Plone
This example is taken out of plone.app.widgets:
adapter = Zope2RequestAdapter(req) tus = Tus(adapter, **tus_settings) if tus.valid: tus.handle() if not tus.upload_finished: return else: filename = req.getHeader('FILENAME') if tus.send_file: filedata = req._file else: filepath = req._file.read() filedata = open(filepath) tus.cleanup_file()
WSGI Filter
Example in python:
from tus import Filter as TusFilter filtered = TusFilter(app, tmp_file_dir='/tmp', upload_path='/upload')
WSGI Paste Configuration Example
Basic paste deploy config:
[app:main] use = egg:MyEgg filter-with = tus [filter:tus] use = egg:tus#main upload_path = /upload tmp_file_dir = /tmp
or:
[filter:tus] use = egg:tus#main upload_path = /upload tmp_file_dir = /tmp [app:main] pipeline = tus egg:MyEgg
0.0
Initial version
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
File details
Details for the file tus-1.0a1.zip
.
File metadata
- Download URL: tus-1.0a1.zip
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26f86352a9dd7f52351f54ead80d79a469378c442ce97dd5ef99160dffaba816 |
|
MD5 | e276f0d9b46c5a77eaede454fc4e0cbe |
|
BLAKE2b-256 | ed88bbc06ee5e9512a9bd8316e94c19583b756f040a5ccebce7c4ffc52fd8f19 |