WebApi File Upload

Source: Internet
Author: User

1. Note that adding the enctype = "Multipart/form-data" property to the form form will cause the action's parameter HttpPostedFileBase object to receive no files.

2. Note The file size, IIS default upload file size is 4MB, more than this size of files need to modify the configuration file.

3. If "Js/jquery.mobile.min.js" is quoted, add data-ajax= "false" to the form form, otherwise the uploaded file will not be received.

if(!Request.Content.IsMimeMultipartContent ()) {                Throw Newhttpresponseexception (Httpstatuscode.unsupportedmediatype); }            stringRoot =@"c:/"; varProvider =NewMultipartformdatastreamprovider (root); Try{StringBuilder SB=NewStringBuilder (); varTask =Request.Content.ReadAsMultipartAsync (provider); Task.                Wait (); foreach(varFileinchprovider. FileData) {FileInfo FileInfo=NewFileInfo (file.                    LocalFilename); Sb. Append (string. Format ("uploaded file: {0} ({1} bytes) \ n", Fileinfo.name, fileinfo.length)); }                return NewHttpresponsemessage () {Content=Newstringcontent (sb.)            ToString ())}; }            Catch(System.Exception e) {returnRequest.createerrorresponse (Httpstatuscode.internalservererror, E); }
View Code

WebApi File Upload

Related Article

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.