react-dropzone / react-dropzone

Simple HTML5 drag-drop zone with React.js.

Home Page:https://react-dropzone.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

file.path is undefined

anthonyraymond opened this issue · comments

Do you want to request a feature or report a bug?

  • I found a bug
  • I want to propose a feature
  • improve documentation

What is the current behavior?
The plugin 'looks' broken in recent browsers. We can't access file.path
2017-08-08 00_04_18-joal ui - development build

If this is a feature request, what is motivation or use case for changing the behavior?

Browsers are hidding file path intentionally for security purpose.
If you want to access file content (don't bother trying to get the path, you can't get it). Use the FileReader API like so:

const reader = new FileReader();
reader.onload = () => {
  const fileAsBinaryString = reader.result;
 // do whatever you want with the file content
};
reader.onabort = () => console.log('file reading was aborted');
reader.onerror = () => console.log('file reading has failed');

reader.readAsBinaryString(file);

This sample uses es6 syntax and filereader api to read file content.
readAsBinaryStringis not the only method available, check the link above.


I think this should be added to the readme and the example should be updated as well.

Please mention other relevant information such as the browser version, Operating System and react-dropzone version.
react-dropzone 3.13.3 and 4.0.0
Google Chrome: 60.0.3112.90
OS: Windows

I'm not sure what you're proposing exactly but I think this is a duplicate of #459

I was asking if you could add an example of filereader api in the readme. Because new browsers version dont set the property path on file objects anymore.
To avcess file content youu must now use the filereader api.

I'm not sure how this example will help solving the issue. Some Dropzone functionality relies on file.path and might not work properly. See linked issue.

If you want to add something the README, please send me a PR.

Actually it's not really for solving anything.

In one of my apps, i need to read the content of dropped files, on previous browsers version i was using fs.readFileSync(file.path).
But new browsers versions prevent usage of file.path (probably for security reasons). The new solution to access file's content is to use the FileReader API.

The issue was more about adding a warning in the readme that file should be accessed with filereader API in the onDrop() callback.

Not sure i could open a PR soon, but i'll try to do when i'll get some time.

@okonet Just created a PR #481