Storing pdf / image or both files in database not in storage/folder in django

325 Views Asked by At

I want to store images and pdf files in the database directly and not in the folder storage, what field type should be given in models along with other information which will be stored in another table and files will be stored in another table of the database. and also how to retrieve those files and view file in later time. I understand its a not advisable but for my requirements i need to do it in this way please let me know how to select files from the template and store the file in database along with other form information.

#django #fileupload

tried looking for multiple resources which all were showing to store files in storage

1

There are 1 best solutions below

0
Amin Malek Mohammadi On

it's not a good or sensible idea to save files(any kind in database) due files are larg amount of data (0 and 1) and it will be hard to save and maintan the database with lots of data that its not human readble I suggest you to read this link why-storing-files-database-bad-practice for enterprise level back-ends you can use object storage like min io but in small apps it's not very unpractical to save files in server alongside your python files.you can you FileField that django can handle you this stuffs django file field