Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/upload/src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion packages/upload/src/upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -92,6 +92,10 @@ export default {
if (before && before.then) {
before.then(processedFile => {
const fileType = Object.prototype.toString.call(processedFile);

processedFile.name = rawFile.name;
Copy link
Contributor

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.

Copy link
Contributor Author

@fengyuanchen fengyuanchen May 18, 2018

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;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Contributor

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.

processedFile.uid = rawFile.uid;

if (fileType === '[object File]' || fileType === '[object Blob]') {
this.post(processedFile);
} else {
Expand Down