Home > Back-end >  How to Store Image file temporary in Django
How to Store Image file temporary in Django

Time:10-02

I am working on django rest framework API, receive a image. I want to delete images after processing. I am not using any database.

CodePudding user response:

I think you may need this:


class YourViewSet(GenericViewSet):
    def create(self, request, *args, **kwargs):
        file_uploaded = request.FILES['filename']
        process_file(Image.open(file_uploaded))
        return Response(status.HTTP_200_OK)

If I'm remembering it correctly, Django would store the uploaded files within memory if the file is smaller than 2MB, or it will store in a temp directory, which will be cleaned up by django process itself. Also, check out the documents here: File Uploads

CodePudding user response:

Tempfile library is what you seek :)

  • Related