Skip to content

Conversation

@fengyuanchen
Copy link
Contributor

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow Element's contributing guide (中文 | English | Español).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer relative issues for you PR.

@element-bot
Copy link
Member

element-bot commented May 17, 2018

Deploy preview for element ready!

Built with commit 6b811a9

https://deploy-preview-11210--element.netlify.com

@Leopoldthecoder
Copy link
Contributor

Please write a demo of the bug you're trying to fix.

@fengyuanchen
Copy link
Contributor Author

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.

@fengyuanchen
Copy link
Contributor Author

fengyuanchen commented May 17, 2018

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 'blob' (without extension) by default after upload the compressed image file, but we may want a valid name as 'example.jpg'.

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

@fengyuanchen
Copy link
Contributor Author

In line 84 of upload.vue, the second argument is not used, so I remove it.

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.

@Leopoldthecoder Leopoldthecoder merged commit 117f731 into ElemeFE:dev May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants