A DRF app upload files easily
Project description
A reusable django library to handle file upload with the Django Rest Framework.
It provides views, serializers and models for simplifying file uploads and their model association in your RESTful application.
How it works
Upload the file using this library multi-part APIs:
POST https://example.com/api/upload/ # A multipart request with a `file` field that contains your file
If upload is complete, an unique identifier for that file is returned, along an URL for accessing it:
{ "url": "https://example.com/media/upload/file.png", "uuid: "1ad29aa9-d470-442d-a5a3-5922e7ce0182" }
Use the uuid in your APIs for associating the uploaded file with your django model instance:
POST https://example.com/api/foo/ { [...], "my-file-attribute": "1ad29aa9-d470-442d-a5a3-5922e7ce0182" }
If you want to update the resource but leave the file unchanged, simply pass the file url as value:
PUT https://example.com/api/foo/2/ { [...], "my-file-attribute": "https://example.com/media/upload/file.png" }
Quick start
Add “drf_file_upload” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'drf_file_upload', ]
Include the polls URLconf in your project urls.py like this:
path('upload/', include('drf_file_upload.urls')),
This will add both separate authenticated and anonymous users to file upload endpoints. Todo: add single view examples
Add the UploadedFileField to your serializers todo
Run python manage.py migrate to create the file upload models.
Run the cleanup management command deleted_expired_uploaded_files in a cron task or add a celery task
TODO: Improve https://docs.djangoproject.com/en/3.1/intro/reusable-apps/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for drf_file_upload-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a7030c5603c60d64457fb004282f67bfefc0c7d0913aafa6d6acc9e86f02c57 |
|
MD5 | f16f174073b885eb7760b898adf1d7bd |
|
BLAKE2b-256 | 2e0564c220d146f5016b93d65d396d180597321a66a77ac214afa5053c788691 |