Skip to content

Uploads large files to Django in multiple chunks, with the ability to resume if the upload is interrupted.

Notifications You must be signed in to change notification settings

emencia/django-chunked-upload

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

django-chunked-upload

This simple django app enables users to upload large files to Django in multiple chunks, with the ability to resume if the upload is interrupted.

This app is intented to work with JQuery-File-Upload by Sebastian Tschan.

Typical usage

  1. An initial POST request is sent to the url linked to ChunkedUploadView (or any subclass) with the first chunk of the file. The key of this chunk can be overriden in the view (class attribute field_name). Example:

     {'my_file': <File>}
    
  2. In return, server with response with the upload_id, the current offset and the when will the upload expire (expires). Example:

     {'upload_id': '5230ec1f59d1485d9d7974b853802e31',
      'offset': 10000,
      'expires': '2013-07-18T17:56:22.186Z'}
    
  3. Repeatedly POST subsequent chunks using the upload_id to identify the upload to the url linked to ChunkedUploadView (or any subclass). Example:

     {'upload_id': '5230ec1f59d1485d9d7974b853802e31',
      'my_file': <File>}
    
  4. Server will continue responding with the upload_id, the current offset and the expiration date (expires).

  5. Finally, when upload is completed, a POST request is sent to the url linked to ChunkedUploadCompleteView (or any subclass). This request must include the upload_id and the md5 checksum (hex). Example:

     {'upload_id': '5230ec1f59d1485d9d7974b853802e31',
      'md5': 'fc3ff98e8c6a0d3087d515c0473f8677'}
    
  6. If everything is OK, server will response with status code 200 and the data returned in the method get_response_data (if any).

Possible errors:

  • User is not authenticated. Server responds 403 (Forbidden).
  • Upload has expired. Server responds 410 (Gone).
  • upload_id does not match any upload. Server responds 404 (Not found).
  • No chunk file is found in the indicated key. Server responds 400 (Bad request).
  • Request does not contain Content-Range header. Server responds 400 (Bad request).
  • Offsets does not match. Server responds 400 (Bad request).
  • md5 checksums does not match. Server responds 400 (Bad request).

Settings

Add any of these variables into your project settings to override them.

CHUNKED_UPLOAD_EXPIRATION_DELTA

  • How long after creation the upload will expire.
  • Default: datetime.timedelta(days=1)

CHUNKED_UPLOAD_PATH

  • Path where uploading files will be stored until completion.
  • Default: 'chunked_uploads/%Y/%m/%d'

CHUNKED_UPLOAD_STORAGE_CLASS

  • Storage system (should be a class).
  • Default: None (use default storage system)

CHUNKED_UPLOAD_ABSTRACT_MODEL

CHUNKED_UPLOAD_ENCODER

  • Function used to encode response data. Receives a dict and returns a string.
  • Default: DjangoJSONEncoder().encode

CHUNKED_UPLOAD_MIMETYPE

  • Mimetype for the response data.
  • Default: 'application/json'

Support

If you find any bug or you want to propose a new feature, please use the issues tracker. I'll be happy to help you! :-)

About

Uploads large files to Django in multiple chunks, with the ability to resume if the upload is interrupted.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%