-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[custom-handler] Allow specifying a custom file reader handler #22
base: master
Are you sure you want to change the base?
Conversation
File reading is not my thing but would this line const blob = file.getAsFile ? file.getAsFile() : file; be better served before the |
@Nolence Let me update the PR. |
@Nolence have a look now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Ken, first off, thanks for working on this. I used to go to school at the U and was always running about Salt Lake, but it's rare that I meet another Utahn online.
It seems like this line is disregarding a lot of valid cases:
if (!file.getAsFile) {
// dragged object is not a file
return;
}
As files themselves don't have that method, only vague DataTransferItems. Here's what I had in mind:
const blob = file.getAsFile ? file.getAsFile() : file;
if (!(blob instanceof Blob)) {
// dragged object is not a file
return;
}
// defer to custom file reader handler if specified
if (typeof this.options.fileReader === "function") {
this.options.fileReader(blob, callback);
return;
}
// otherwise set up file reader
const reader = new FileReader();
reader.onload = evt => {
callback(evt.target.result);
};
// read the clipboard item or file
reader.readAsDataURL(blob);
I tested this on FireFox, Chrome and Edge. Edge didn't seem to support drag and drop but that seems like a wholly different PR.
Is this going to be merged? Doesn't seem to be any issues but it's been almost three months. |
No description provided.