Django Dropbox Upload Handler
Transfer Uploaded Files to Dropbox
Quickstart
Install Django Dropbox Upload Handler:
pip install django-dropbox-upload-handler
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'django_dropbox_upload_handler.apps.DjangoDropboxUploadHandlerConfig',
...
)
Add DropboxFileUploadHandler to the default Upload Handlers:
FILE_UPLOAD_HANDLERS = [
'django_dropbox_upload_handler.handler.DropboxFileUploadHandler'
]
To Enable DropboxFileUploadHandler within a single view:
forms.py
from django import forms
class UploadFileForm(forms.Form):
title = forms.CharField(max_length=50)
file = forms.FileField()
views.py
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import UploadFileForm
# Imaginary function to handle the uploaded file dropbox file.
from somewhere import handle_uploaded_file
def upload_file(request):
if request.method == 'POST':
self.request.upload_handlers.insert(0, DropboxFileUploadHandler(request))
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['file'])
return HttpResponseRedirect('/success/url/')
else:
form = UploadFileForm()
return render(request, 'upload.html', {'form': form})
Add Django Dropbox Upload Handler’s URL patterns:
from django_dropbox_upload_handler import urls as django_dropbox_upload_handler_urls
urlpatterns = [
...
url(r'^', include(django_dropbox_upload_handler_urls)),
...
]
Checking upload progress for API:
When submitting the file include the parameter progres_id in the URL. ex:
function getUUID() {
let uuid = ""
for (let i=0; i < 32; i++) {
uuid += Math.floor(Math.random() * 16).toString(16);
}
return uuid
}
function upload(file) {
let data = new FormData()
data.append('file', file)
fetch('/path/to/upload?progress_id=' + getUUID(), {
method: "post",
body: data
})
.then(response => {
//...
})
checkProgress(0, progressId, file.size)
}
function checkProgress(progressId, size) {
fetch('/upload_progress?progress_id=' = progiressId)
.then(response => {
if (r.status === 201)
return {done: 'true'}
return response.json()
})
.then(data => {
if (data.done) {
//..upload is completed
} else {
//.. still uploading - progress can be checked using:
progress = Math.round(parseInt(data.uploaded) / parseInt(data.length) * 100)
setTimeout(() => { checkProgress( progressId, size) }, 500)
}
})
}
Features
Transfers files uploaded through Django to Dropbox
Includes a upload_progress view for ajax calls
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Credits
Tools used in rendering this package:
History
0.1.0 (2017-09-03)
First release on PyPI.
Metadata
Release files for django-dropbox-upload-handler 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-dropbox-upload-handler-0.1.1.tar.gz | 7.7 kB | Without provenance | Details for django-dropbox-upload-handler-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_dropbox_upload_handler-0.1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for django_dropbox_upload_handler-0.1.1-py2.py3-none-any.whl |
Total release size: 15.9 kB
Release files / django-dropbox-upload-handler-0.1.1.tar.gz
| Download URL | django-dropbox-upload-handler-0.1.1.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36f3218c9337f77aab26651565e3864e38896a6bec501c94606903302bf591f6
|
|
BLAKE2b-256 checksum How to use checksums |
0ea99238ad2709b69511f9cb459e0f95c48ff5a337de1cff1443aa1e5d68d878
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_dropbox_upload_handler-0.1.1-py2.py3-none-any.whl
| Download URL | django_dropbox_upload_handler-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
52faf7b8b4c561eb898decb4468e1c41346d1a217b3d7439d95f25305569c42d
|
|
BLAKE2b-256 checksum How to use checksums |
6357b1d5dfa367dcd1ff4b98e699e7804337023b3848dde0c1af29cb493f2416
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-dropbox-upload-handler 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.