Skip to main content

Django resumable uploads

Project description

django-resumable

https://drone.io/github.com/jeanphix/django-resumable/status.png

django-resumable provides django backend stuff that handles resumable.js xhr uploads.

Installation

  • pip install django-resumable

  • Add resumable to your INSTALLED_APPS

Views

In order to upload files asynchronous, you must define an endpoint that will deal with uploaded file chunks:

from django.contrib.auth.decorators import login_required

from resumable.views import ResumableUploadView


urlpatterns += patterns('',
    url('^upload/$', login_required(ResumableUploadView.as_view()),
        name='upload'),
)

You should also consider having per user chunk upload directory:

class MyResumableUploadView(ResumableUploadView):
    @property
    def chunks_dir(self):
        return self.request.user.profile.chunks_dir

Fields

If you want to handle resumable upload within your forms, you can use the ResumableFileField that works like django core FileField:

from django.conf import settings
from django.core.urlresolvers import reverse

from resumable.fields import ResumableFileField


class ResumableForm(Form):
    file = ResumableFileField(
        allowed_mimes=("audio/ogg",),
        upload_url=lambda: reverse('upload'),
        chunks_dir=getattr(settings, 'FILE_UPLOAD_TEMP_DIR')
    )

Javascript

django-resumable comes with extendable frontend scripts that work out of the box:

{% load staticfiles %}
<!DOCTYPE html>
<html>
    <body>
        <form method="post" action=".">
            <fieldset>
                {% csrf_token %}
                {{ form.as_p }}
            </fieldset>
            <p><input type="submit" value="send" /></p>
        </form>
        <script type="text/javascript" src="https://raw.github.com/23/resumable.js/master/resumable.js"></script>
        <script type="text/javascript" src="{% static 'resumable/js/django-resumable.js' %}"></script>
        <script type="text/javascript" src="{% static 'resumable/js/init.js' %}"></script>
    </body>
</html>

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-resumable-0.1.tar.gz (15.0 kB view details)

Uploaded Source

File details

Details for the file django-resumable-0.1.tar.gz.

File metadata

File hashes

Hashes for django-resumable-0.1.tar.gz
Algorithm Hash digest
SHA256 4c65e5cc17b01ca41a8f9666d6afe7c37ed5d0748a0e516e47b0d53a6d19a503
MD5 d4bafff1adfc6743eac2dcd4071fa9ae
BLAKE2b-256 8257a179d457419162b6a3840aa5ef9b6c7b188e503f8aba93ab0090cc41acfe

See more details on using hashes here.

Supported by

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