Skip to main content

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

  1. 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
  2. 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"
    }
  3. 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"
    }
  4. 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

  1. Add “drf_file_upload” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'drf_file_upload',
    ]
  2. 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

  1. Add the UploadedFileField to your serializers todo

  2. Run python manage.py migrate to create the file upload models.

  3. 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

Metadata

Release files for drf-file-upload 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drf-file-upload 0.1.5
File Size Uploaded
drf_file_upload-0.1.5.tar.gz 15.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drf-file-upload 0.1.5
File Interpreter ABI Platform
drf_file_upload-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 38.0 kB

Release files / drf_file_upload-0.1.5.tar.gz

Download URL drf_file_upload-0.1.5.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7ff3235bed9801dffcf295d6d37564a33c2fe7c9ae6829e177ef20d23988c52e
BLAKE2b-256 checksum
How to use checksums
61a71310130ad94a99f7f1971ac4b56dc955961303c2aaf268822f5febe3ed4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 10, 2025.

Transparency log

Release files / drf_file_upload-0.1.5-py3-none-any.whl

Download URL drf_file_upload-0.1.5-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
024ab1b939b39110f3c8dad778e1ab1ff8f9366d0097cc3478b9d4426973a92c
BLAKE2b-256 checksum
How to use checksums
6a62f4817265cb89c7704d2528eb86a54c64a90f69db60c955b314937c6a0e7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 10, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page