Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  66] [ 2]  / answers: 1 / hits: 8556  / 9 Years ago, sat, june 20, 2015, 12:00:00

I am busy building a small gallery that is pulled from my local file system. I have an element that gets the directory:



    <input type=file webkitdirectory>


I then display all the images and videos in that directory on the page in a container.



At the moment for security reasons I only have access to the relative path so I had to add a hardcoded e:/downloads for it to find the files when I display them because the location of the file is on my desktop.



I want to extend this so I can choose a directory from anywhere on my local file system, but I need the aboslute path. Currently only IE gets me the absolute path, chrome returns a fakepath. I know how to get to the settings to allow local file system files to be included in IE, but I don't know how to enable it in Chrome. I would like to know if there is an option to allow this like in IE.



I have done searches around and most people say it is not possible, however I believe there must be a setting somewhere, I am hoping someone knows.



Here is my code just for kicks if you want to have a look:
https://jsfiddle.net/3mp1znx9/



Please note because it is hardcoded to e:/downloads you might want to change it to make it work for you.



You can open up the console and run the function called GetDirectory if you want to see the absolute path it tries to return. (you should also comment out the removal of the element after it has changed as well)



I hope my question was clear and not too long. Thank you.



Summary:

I want to access the absolute path of my local files from the element within Chrome. I can already do it in IE.


More From » jquery

 Answers
3

I finally found a solution to my own problem. It is nearly impossible to get the absolute path with Chrome, it only works with Internet Explorer.



So the solution is to use the temporary path.



URL.createObjectURL(e.target.files[0])


This is what was needed, I then use this as the src. I hope this will help someone else when they stumble upon this one day.


[#36220] Friday, June 19, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rossthomasn

Total Points: 122
Total Questions: 78
Total Answers: 105

Location: South Georgia
Member since Sun, Aug 8, 2021
3 Years ago
rossthomasn questions
Wed, Mar 16, 22, 00:00, 2 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Thu, Nov 26, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
;