Skip to content

file.path is undefined #477

@anthonyraymond

Description

@anthonyraymond

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions