-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Upload: fix a TypeError when upload a processed file from the beforeUpload hook
#11210
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
Conversation
|
Deploy preview for element ready! Built with commit 6b811a9 |
|
Please write a demo of the bug you're trying to fix. |
|
Here is a demo: https://jsfiddle.net/cfy/53jf2oms/1/ Open the console and choose an image to upload, and then you will see a TypeError in the console. |
|
In line 56 of ajax.js, I also add the file name to the form data, just because if miss it, the server side will get a file with the name of Reference: https://developer.mozilla.org/en-US/docs/Web/API/FormData/append |
|
In line 84 of upload.vue, the second argument is not used, so I remove it. |
packages/upload/src/upload.vue
Outdated
| before.then(processedFile => { | ||
| const fileType = Object.prototype.toString.call(processedFile); | ||
| processedFile.name = rawFile.name; |
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.
Is this line necessary? Because here processedFile already has a name prop.
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.
A blob object only has two properties: size and type. In the given demo, the name property is assigned by the image compressor.
Improved version:
// Allow user to customize the processed file name
processedFile.name = processedFile.name || rawFile.name;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.
OK
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.
This change will cause an error if here the processedFile is still a File object.
Please make sure these boxes are checked before submitting your PR, thank you!
devbranch.