4

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">
Tarlen
  • 3,657
  • 8
  • 30
  • 54
  • 1
    This is for security reasons, you can't get the full file path on the local computer of the one sent it. – D4V1D Mar 27 '15 at 20:16
  • Provide the code you are using to send the information to node, as well as the code you are using in node to accept said information. You should not need the filepath to the file on the user's machine to send to the youtube api from node. – Kevin B Mar 27 '15 at 20:16
  • 1
    possible duplicate of [how to resolve the C:\fakepath?](http://stackoverflow.com/questions/4851595/how-to-resolve-the-c-fakepath) – blurfus Mar 27 '15 at 21:29
  • [Solution of fake path --> Error S](https://stackoverflow.com/a/65603878/13723867) – Musawar ahmed Jan 06 '21 at 22:05

1 Answers1

8

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.

Community
  • 1
  • 1
Bruno Toffolo
  • 1,504
  • 19
  • 24
  • 1
    So how does one get the file to upload if I can't see the file path. I am having the same issue now trying to upload to cloudinary from my nod.js app – David Essien Oct 10 '18 at 12:55