New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

drf-file-upload

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drf-file-upload

A DRF app upload files easily

  • 0.1.5
  • PyPI
  • Socket score

Maintainers
2

=============== 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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc