Skip to main content

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

Project description

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 (documentation).

License: MIT-Zero.

Demo

If you want to see a very simple Django demo project using this module, please take a look at django-chunked-upload-demo.

Installation

Install via pip:

pip install django-chunked-upload

And then add it to your Django INSTALLED_APPS:

INSTALLED_APPS = (
    # ...
    'chunked_upload',
)

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 name of the chunk file can be overriden in the view (class attribute field_name). Example:

{"my_file": <File>}
  1. 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. Important: For each subsequent chunk, include the Content-Range header to specify the byte range being uploaded. 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>
}
  1. Server will continue responding with the upload_id, the current offset and the expiration date (expires).

  2. 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"
}
  1. If everything is OK, server will response with status code 200 and the data returned in the method get_response_data (if any).

Possible error responses:

  • 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).

  • Size of file exceeds limit (if specified). 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_TO

  • upload_to to be used in the Model’s FileField.

  • Default: CHUNKED_UPLOAD_PATH + '/{{ instance.upload_id }}.part'

CHUNKED_UPLOAD_STORAGE_CLASS

  • Storage system (should be a class).

  • Default: None (use default storage system)

CHUNKED_UPLOAD_ENCODER

  • Function used to encode response data. Receives a dict and returns a string.

  • Default: DjangoJSONEncoder().encode

CHUNKED_UPLOAD_CONTENT_TYPE

  • Content-Type for the response data.

  • Default: 'application/json'

CHUNKED_UPLOAD_MAX_BYTES

  • Max amount of data (in bytes) that can be uploaded. None means no limit.

  • Default: None

CHUNKED_UPLOAD_MODEL_USER_FIELD_NULL

  • Value of null option in user field of ChunkedUpload model

  • Default: True

CHUNKED_UPLOAD_MODEL_USER_FIELD_BLANK

  • Value of blank option in user field of ChunkedUpload model

  • Default: True

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! :-)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_chunked_upload_patched-2.1.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_chunked_upload_patched-2.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file django_chunked_upload_patched-2.1.0.tar.gz.

File metadata

File hashes

Hashes for django_chunked_upload_patched-2.1.0.tar.gz
Algorithm Hash digest
SHA256 cdbdf56391e384163ac5453b6d6c824938e853c2b0dd2b774dd19fe438d6fd30
MD5 b6d6eb37e8c2e168e6a608a5a72f3694
BLAKE2b-256 af4b16d7fe14ede71fb83d7d65d3b89754ab43a329f7ec87b47be437df2b12cc

See more details on using hashes here.

File details

Details for the file django_chunked_upload_patched-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_chunked_upload_patched-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48ecf29d8b6106c2c31e8eb21174e642fec7176283e40e307a884f58df809808
MD5 29ff75e6b4c7ce482a34983d75c4b0c9
BLAKE2b-256 89992c16b636fa77a679b6d7092dcbce510bfeed565e7dddb04c0b9df376bbc9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page