Ajax uses Formdata to upload files asynchronously, error The request was rejected because no multipart boundary was found

Source: Internet
Author: User

jquery-based AJAXS use Formdata to upload files note the two parameter settings

ProcessData set to False

Set ProcessData to False so that jquery does not handle formdata, and if ProcessData is not set to false,jquery the Formdata is converted to a string.

ContentType set to False

Example of HTTP sending Multipart/form-data request message

post/api/feed/http/1.1accept-encoding:gzipcontent-length:225873Content-type:multipart/form-data; boundary= OCQXMF6-JXTXOMDHMOG5W5EY9MGRSTBPHost:www.myhost.comConnection: Keep-alive--ocqxmf6-jxtxomdhmog5w5ey9mgrstbpcontent-disposition:form-data; Name= "LNG" content-type:text/plain; Charset=utf-8content-transfer-encoding:8bit116.361545--ocqxmf6-jxtxomdhmog5w5ey9mgrstbpcontent-disposition: Form-data; Name= "lat" content-type:text/plain; Charset=utf-8content-transfer-encoding:8bit39.979006--ocqxmf6-jxtxomdhmog5w5ey9mgrstbpcontent-disposition: Form-data; Name= "Images"; Filename= "/storage/wbavrx.jpg" content-type:application/octet-streamcontent-transfer-encoding: Binary here is the binary data of the picture--ocqxmf6-jxtxomdhmog5w5ey9mgrstbp--

  

Note Content-Type: multipart/form-data; boundary=OCqxMF6-JxtxoMDHmoG5W5eY9MGRsTBp that the parameter boundary is the bounds identifier between the request parameters.

If the jquery request is set to ContentType, then the Formdata content-type is overwritten, causing the server to be unable to find boundary when separating the parameters and the contents of the file, reporting an no multipart boundary was found error

By default, jquery sets ContentType to application/x-www-form-urlencoded. To jquery without setting contenttype, you need to set ContentType to false.

var formData = new FormData ($ ("#uploadform") [0]), $.ajax ({    url:actionurl,    type: ' POST ',    data:formdata,    Async:false,    cache:false,    contenttype:false,    processdata:false,    ...});

  

Ajax uses Formdata to upload files asynchronously, error The request was rejected because no multipart boundary was found

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.