Resolved: How to get the real file path in React

In this post, we will see how to resolve How to get the real file path in React


I use this function to get the file name, however it shows C:\fakepath\myfile.jpg.
I understand this is security reason, however when I upload the file. I need full path.
How can I get the full path by React??

Best Answer:

In any JavaScript executed in the browser, you cannot directly access the file system of the client’s device. This is due to security restrictions imposed by web browsers to prevent malicious scripts from accessing sensitive information on the client’s computer.
The term “fakepath” is used to replace the missing file path.
While as a developer this may seem like a restriction, as a user, you do not want websites having any form of access to your device’s directory.

If you have better answer, please add a comment about this, thank you!