A DRF app upload files easily
Project description
DRF File Upload
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/
TODOs & IDEAS
Add support for Image file
check if DRF dedicated fields can be exploited
lots of config (e.g. permission_classes)
check if clean_uploaded_files can be called somewhere else to avoid save method override
Documentation!
Check if the file field can be set globally for all model FileFields
Add better spectacle openapi docs
Add missing tests
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
File details
Details for the file drf_file_upload-0.1.4.tar.gz
.
File metadata
- Download URL: drf_file_upload-0.1.4.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a5daf5d906ebc941159080774293f8ef36c7f6dcf11b2003f0604d8abb023cb |
|
MD5 | 83224a2ec452f9479c87d07c0728877f |
|
BLAKE2b-256 | f73f64626d9cb44001a4769eb4194be32e4f5e1a8793c5e89ae6d9b83eb86ef5 |
File details
Details for the file drf_file_upload-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: drf_file_upload-0.1.4-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 615baf4d0476aa6902d6b9217115a21d2280c40c04a93756416d547384da3eb1 |
|
MD5 | 0ef5f936c4a567d48ec1cf24aa133986 |
|
BLAKE2b-256 | 8b9bcfe1354f7e8845acb8bbccdcf58b5dedbc023feb06c3c52882852c0f8521 |