input type file onchange in the process of uploading files, encountered the same file two times the issue of invalid upload.

Source: Internet
Author: User

Do not delete the current Input[type=file] This node, and then re-create the DOM this scenario, this is unreasonable.

The explanations are as follows:
Input[type=file] Use onchange to do, onchange listen to the value of input, only when the content changes to trigger the time, and value in the upload file is the content of the file, you only need to upload the successful callback inside To empty the value of the current input.
Event.target.value= ";
Getinputfile (event) {
if (event.target.files.length) {
Let FormData = new FormData ()
Formdata.append ("File", Event.target.files[0])
this. $http ({
Method: ' Post ',
Async:true,
Crossdomain:true,
Url:${this.api.uploadData.uploadUrl},
Headers: {
"Cache-control": "No-cache",
"Postman-token": "19899c72-855a-49a1-494b-fe42b45d5d5e"
},
Processdata:false,
Contenttype:false,
Cors: {
All requests is expected to be cross-domain requests
Expected:true,
If you want cookie to being sent along with the request
Sendcredentials:true
},
MimeType: "Multipart/form-data",
Data:formdata
}). Then (res = {
if (!res.data.data.errtotal) {
This.curmask = True
This.uploadsuccess = True
This.uploadfail = False
}else{
This.curmask = True
This.uploadfail = True
This.uploadsuccess = False
This.errnumber = Res.data.data.errTotal
This.errurl = Res.data.data.errUrl
}
Event.target.value= "
}). catch (E = = {
Event.target.value= "
this. $alert (e.response.data.msg)
})
}
}

input type file onchange in the process of uploading files, encountered the same file two times the issue of invalid upload.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.