Commit 117f731f authored by Fengyuan Chen's avatar Fengyuan Chen Committed by 杨奕

Upload: fix a TypeError when upload a processed file from the `beforeUpload` hook (#11210)

* Upload: add filename

Reference: https://developer.mozilla.org/en-US/docs/Web/API/FormData/append

* Upload: add name and uid properties to processedFile to fix an error

* Update upload.vue
parent 4d545695
...@@ -53,7 +53,7 @@ export default function upload(option) { ...@@ -53,7 +53,7 @@ export default function upload(option) {
}); });
} }
formData.append(option.filename, option.file); formData.append(option.filename, option.file, option.file.name);
xhr.onerror = function error(e) { xhr.onerror = function error(e) {
option.onError(e); option.onError(e);
......
...@@ -81,7 +81,7 @@ export default { ...@@ -81,7 +81,7 @@ export default {
if (this.autoUpload) this.upload(rawFile); if (this.autoUpload) this.upload(rawFile);
}); });
}, },
upload(rawFile, file) { upload(rawFile) {
this.$refs.input.value = null; this.$refs.input.value = null;
if (!this.beforeUpload) { if (!this.beforeUpload) {
...@@ -92,7 +92,10 @@ export default { ...@@ -92,7 +92,10 @@ export default {
if (before && before.then) { if (before && before.then) {
before.then(processedFile => { before.then(processedFile => {
const fileType = Object.prototype.toString.call(processedFile); const fileType = Object.prototype.toString.call(processedFile);
if (fileType === '[object File]' || fileType === '[object Blob]') { if (fileType === '[object File]' || fileType === '[object Blob]') {
processedFile.name = rawFile.name;
processedFile.uid = rawFile.uid;
this.post(processedFile); this.post(processedFile);
} else { } else {
this.post(rawFile); this.post(rawFile);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment