Package: django2-resumable
Django 2.x Resumable (django-resumable)django2-resumableprovidesDjango 2.1backend stuff (e.g.ModelFields,Forms,staticfiles)
to integratesresumable.jsin Django apps and admin.This projects build on the originaldjango-resumablebyjeanphix, which (afaik) it
is not maintained anymore, and does not support Django 2.x -main
reason why I ended up developing this in the first place(ed.)ICYM:(from thedocumentation)Resumable.js is a JavaScript library providing multiple simultaneous, stable and
resumable uploads via theHTML5 File API.The library is designed to introduce fault-tolerance into the upload of large files through HTTP.
This is done by splitting each file into small chunks.
Then, whenever the upload of a chunk fails, uploading is retried until the procedure completes.
This allows uploads to automatically resume uploading after a network connection
is lost either locally or to the server.
Additionally, it allows for users to pause, resume and even recover uploads without
losing state because only the currently uploading chunks will be aborted, not the entire upload.Resumable.js does not have any external dependencies other than theHTML5 File API.
This is relied on for the ability to chunk files into smaller pieces.
Currently, this means that support is widely available in to Firefox 4+, Chrome 11+,
Safari 6+ and Internet Explorer 10+.Installationpip install django2-resumableAdddjango2_resumableto yourINSTALLED_APPSHow to useViewsIn order to enable asynchronous files upload files, you must define an endpoint that will deal
with uploaded file chunks:fromdjango.urlsimportpath,includeurlpatterns=[path('resumable_upload/',include('django2_resumable.urls')),]By default, theresume-uploadview is provided with no restriction on the accesses
(i.e. nologin_requirednorstaff_member_required).To enable the view on restricted levels of permissions, urls should be modified accordingly:fromdjango.contrib.auth.viewsimportlogin_required# To enable view in AdminFormfromdjango.contrib.admin.views.decoratorsimportstaff_member_requiredfromdjango2_resumable.viewsimportresumable_uploadfromdjango.urlsimportpathurlpatterns=[path('resumable-upload',login_required(resumable_upload),name='resumable-upload'),path('admin-resumable-upload',staff_member_required(resumable_upload),name='admin-resumable-upload'),]Modeldjango2-resumableprovides aResumableFileFieldthat can be easily
integrated in your Model class:fromdjango.dbimportmodelsfromdjango2_resumable.fieldsimportResumableFileFieldclassMyModel(models.Model):file=ResumableFileField(chunks_upload_to='resumable_chunks',**kwargs)TheResumableFileFieldfield extends the defaultdjango.core.fields.FielFieldby including
an additional parameter, namelychunks_upload_tospecifying the path in theMEDIA_ROOTin which
temporary chunks will be uploaded. Once the upload is complete, the file will be
automatically moved to theupload_todestination folder (if any).FormIf you want to handle resumable upload within your forms,
you can use theFormResumableFileField:fromdjango.formsimportFormfromdjango2_resumable.formsimportFormResumableFileFieldclassResumableForm(Form):file=FormResumableFileField()It is as simple as that:FormResumableFileFieldsimply extends the coredjango.forms.FileFieldby injecting thedjango_resumable.widgets.ResumableWidget.
This widget is the default widget mapped by default toResumableFileFieldinstances
(seedjango_resumable.fields.ResumableFileField.formfieldmethod).Additional Settingsdjango2-resumablecomes with some extendable settings allowing for additional setup:RESUMABLE_SUBDIR: Directory inMEDIA_ROOTin which chunks will be uploaded. This settings will be
overriden by anychunks_upload_tooptions specified at the time of definition ofResumableFileFieldwithin Django Model.RESUMABLE_STORAGE: (defaultdjango.core.files.storage.FileSystemStorage)
Django Storage class to be used to handle the uploads.