0

I'm pretty new to Python\Django.

I'm trying to make a local Netflix-like Library for my Movie\TV shows collection.

The general idea is that the user chooses a media folder, the server side runs on the files in the folder adds them to the database and then the user can search for the items and play them back in the GUI.

The first snag I ran into is getting the folder path from the user without actually uploading any files. After doing some searching online I found this :

<input type="file" id="file_input" webkitdirectory="" directory="">

This HTML code allows the user to choose a folder and iterates through all the files inside, however, I don't know how can I pass this information to views.py so that I could run logic on the input.

Does anyone know how this could be accomplished ?

Curtwagner1984
  • 1,908
  • 4
  • 30
  • 48
  • Is this what you want to do? - http://stackoverflow.com/questions/4706255/how-to-get-value-from-form-field-in-django-framework – Lyman Zerga Jun 07 '16 at 18:38

1 Answers1

1

For security reasons, browsers do not allow to get folder path (Stack Overflow). Since you do not want the user to upload files, the possible solution would be to explicitly mention the folder path in <input type="text">. The simplest solution would be python –m SimpleHTTPServer (source, docs). You may be also interested in this Django app.

Community
  • 1
  • 1
Jomy
  • 368
  • 4
  • 11
  • Thank you, but this ended up uploading the files in the selected folder into a temp upload dir, which is not what I want. I just want to pass the selected dir path. It seems that 'webkitdirectory' is not what I want. – Curtwagner1984 Jun 08 '16 at 13:00
  • I think you are looking for [HTML multiple Attribute](http://www.w3schools.com/tags/att_input_multiple.asp). – Jomy Jun 08 '16 at 15:28
  • If your uploaded file is too large, [Django will write the uploaded file to a temporary file](https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#where-uploaded-data-is-stored). You will have to write [custom upload handlers](https://docs.djangoproject.com/en/dev/ref/files/uploads/#writing-custom-upload-handlers). For performance, you will need to use a server like apache or nginx. – Jomy Jun 08 '16 at 16:10
  • Thing is, I don't want to upload the files at all. If it all possible I just want to pass the dir path to the server. Ideally, it will be a string like "D:\Movies". – Curtwagner1984 Jun 08 '16 at 16:52
  • I don't think it's possible. Please check my updated answer. – Jomy Jun 08 '16 at 20:01
  • Thanks. That is what I'm doing now. Input the explicit path in a input field. I figure later I can have the backend list the dir structure and serve it in a GUI to the user. – Curtwagner1984 Jul 12 '16 at 10:13