Reputation: 3797
I am trying to upload a video to youtube through their API
I use a HTML input field, but for some reason, it gives me a path like
C:\fakepath\..
Why is this and how can I get the right filepath, so I can use it in my request
<input type="file" name="fileName" data-schema-key="fileName">
Upvotes: 4
Views: 18874
Reputation: 1554
This question has already been answered here: How to resolve the C:\fakepath?.
As commented in The Mystery of c:fakepath Unveiled:
According to the specifications of HTML5, a file upload control should not reveal the real local path to the file you have selected, if you manipulate its value string with JavaScript. Instead, the string that is returned by the script, which handles the file information is C:\fakepath.
If you want to leave just the filename (for "beauty" purposes), you can do a simple string replacing operation.
// Change the node's value by removing the fake path
inputNode.value = fileInput.value.replace("C:\\fakepath\\", "");
You can't, however, have access to the original file path. "It makes sense - as a client, you don't want the server to know your local machine's filesystem. It would be nice if all browsers did this", as already pointed out in the SO question I cited in the first line of this answer.
Upvotes: 8