Uploadify combined with Web API 2 upload Problems

Source: Internet
Author: User

Recently, jQuery. Uploadify and Web API are used in combination for upload. If you encounter any problems, you can also solve them. record them as follows:

Environment: jQuery 1.10.2, Uploadify 3.2.1, SWFObject 2.2, Web API 2

Front-end code (JavaScript ):

$ ("# File-upload" "auto": "multi": "buttonText": "select a file" "swf": "/upload.swf" "uploader ": "/api/up" "uploadLimit": 1 "removeCompleted": "onSelect": "# btn-upload "). prop ("disabled", "onCancel": "# btn-upload "). prop ("disabled", "onUploadStart": "Start upload:" + "onUploadSuccess": "Upload [" + file. name + "] successful" "onUploadError": "Upload [" + file. name + "] failed"

Server code (C #)

The ApiController that receives the file:

 System.Web.Http;
  Task<> (!Request.Content.IsMimeMultipartContent(      root = HttpContext.Current.Server.MapPath( provider =  body =  result = body.FileData[ 

Create a CustomMultipartFormDataStreamProvider class inherited from MultipartFormDataStreamProvider to restore the uploaded file name:

  CustomMultipartFormDataStreamProvider(   sb =  StringBuilder((headers.ContentDisposition.FileName ?? DateTime.Now.Ticks.ToString()).Replace(, ).Trim().Replace( , => sb.Replace(invalidChar, 

After the above Code is complete, it can run smoothly. After testing, the file has been successfully uploaded to the server. However, the upload result is always displayed as failed and an error is reported: error writing MIME multipart body part to output stream.

This is strange. After half a day on Google, I found related instructions. It turned out to be a Bug in Web API 2 Framework, which is related to the line break of Flash. On the one hand, wait for the MS to be repaired (the MS is already fixed and is expected to be fixed in Web API 2.1). In addition, you can solve the problem in other ways. If not, record the problem first, and then complete this article.

The following are some discussions and explanations related to MS. All of them are in English. If you are interested, you can check them out.

Foreign discussion (English)

Description of MS Development Team (English)

Another description of the MS Development Team)

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.