Search code examples
djangoweb-applicationslocal-storagefilefield

Retrieve files from local directory in django


I found myself in a situation where a client asked if we can serve the files in the web app withought him uploading them. Instead he wants to drop the files in a local directory. Let's say in '/Desktop/myfiles/'.

Question #1 = Is it possible to rerieve all the files from a local directory? Question #2 = If I can retrieve the files from the local directory how can I store the file_path to store it in a FileField field in mymodel? So When I I write Mymodel.objects.all() I get all the Files!!

PS: Of course I don't know the filenames in advance. That would be a bonus!

Any Ideas?


Solution

  • I managed to pull the files from the local directory using Sql script with LOAD LOCAL INFILE and Update the fields after the insert. To get/crate the correct file path I used CONCAT.
    It works like a charm and actually can be very handy for demanding web apps.