0

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?

Danae Vogiatzi
  • 178
  • 5
  • 23

3 Answers3

0

Maybe set a directory together the static content, then make an ftp user to get access to upload files to that directory, it's all

jesusgn90
  • 563
  • 2
  • 12
0

That's a weird requirement :-) I personally would try to say no and instead implement something with fineuploader that would allow you to support drag and drop for multiple files. But seems that's not the OP:

I would use as side cron job or worker using a management function ('Python manage.py your_function') or implementing Celery to basically search for all files and for every file not already on the database, create a new record for it. To make things simpler, you may want this function to also move the file to your MEDIA location ( rather than making the original directory the MEDIA ).

Basically, using django management or django-celeryfunctions, you can be checking every five minutes ( or every minute ) and doing the equivalent of a User upload.

There is not enough description of your code for me to write sample cod but hopefully you get the idea.

dkarchmer
  • 5,434
  • 4
  • 24
  • 37
  • I am not familiar with Celery at all!! So you basically speaking chinese to me now ;) . i know it's a weird requirement. I am leaning to 'no' but I had to do my research first. Thanks for the info! – Danae Vogiatzi Jan 21 '17 at 13:48
0

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.

Danae Vogiatzi
  • 178
  • 5
  • 23