I have the django form where user attach the files, but I am extracting the pdf form data from the file itself so I don’t want to save the file.
But when I save the form then file automatically gets saved. Is there any way to prevent the file from being saved?
thanks
When a file is being uploaded to your server, django handles the uploaded file depending on the
FILE_UPLOAD_HANDLERyou specify. By default, they are:-which means that the file object is in your server’s memory until
form.save()(where theformobject contains your uploaded file) is called. Once it is called, the file object is written into your filesystem based on what you specified in that file field’supload_toattribute.What I would do to prevent this uploaded file from being written into your filesystem would be to assign this file object to a variable without calling
form.save(). Like this:-and we can deliberately not assign
request.FILES, like this:-Since you have
uploaded_filevariable assigned, you can now do whatever you wish to it without writing it into the filesystem.And since your
forminstance do not haverequest.FILESassigned,form.save()will not write your form data into the filesystem.