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
pull/11245/head
Fengyuan Chen 2018-05-18 14:00:06 +08:00 committed by 杨奕
parent 4d54569542
commit 117f731f6e
2 changed files with 5 additions and 2 deletions

View File

@ -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) {
option.onError(e);

View File

@ -81,7 +81,7 @@ export default {
if (this.autoUpload) this.upload(rawFile);
});
},
upload(rawFile, file) {
upload(rawFile) {
this.$refs.input.value = null;
if (!this.beforeUpload) {
@ -92,7 +92,10 @@ export default {
if (before && before.then) {
before.then(processedFile => {
const fileType = Object.prototype.toString.call(processedFile);
if (fileType === '[object File]' || fileType === '[object Blob]') {
processedFile.name = rawFile.name;
processedFile.uid = rawFile.uid;
this.post(processedFile);
} else {
this.post(rawFile);