Git Product home page Git Product logo

django-resumable's Introduction

django-resumable

Build Status

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>

django-resumable's People

Contributors

jeanphix avatar entequak avatar chubz avatar

Watchers

Wai Yi Anthony Leung avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.