Ionic app upload Image Webapi interface

Source: Internet
Author: User
Tags save file

How does the WEBAPI service side of the app upload image handle?

usingSystem;usingSystem.Collections.Generic;usingSystem.Diagnostics;usingSystem.IO;usingSystem.Linq;usingSystem.Net;usingSystem.Net.Http;usingSystem.Threading;usingSystem.Threading.Tasks;usingsystem.web;usingSystem.Web.Hosting;usingSystem.Web.Http;namespaceionic.app.webapi.controllers{ Public classUploadapicontroller:apicontroller { PublicUploadapicontroller () {} [HttpPost] PublicTaskPost () {if(!Request.Content.IsMimeMultipartContent ()) {                Throw Newhttpresponseexception (Httpstatuscode.unsupportedmediatype); }            //gets the collection of key values for the query string            varQUERYP =Request.getquerynamevaluepairs ();  string root = "c:\\inetpub\\wuzapp\\app_data";            varProvider =NewMultipartformdatastreamprovider (root); //Read the form data            returnRequest.Content.ReadAsMultipartAsync (provider). ContinueWith (t =            {                stringMessage ="Hello"; foreach(Multipartfiledata fileinchprovider. FileData) {trace.writeline (file.                    Headers.ContentDisposition.FileName); Trace.WriteLine ("Server file path:"+file.                    LocalFilename); if(File.exists (File. LocalFilename)) {message=file.                        LocalFilename; //Do some                    }                    Else{message= file. LocalFilename +"no exist"; }                }                returnRequest.createresponse (httpstatuscode.ok,message);        }, Taskscheduler.fromcurrentsynchronizationcontext ()); }    }}

Where the red part is written dead to the path of the specific save file, in the test found in the machine can upload pictures, switch to the server, one can upload a file, but no, suspect is a permission issue.

Add Read/write permissions to the Everyone account that corresponds to this directory, and you can upload it successfully.

This allows you to upload files/images and other content via the app.

Test code for C # Windform end

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Net.Http;usingSystem.IO;usingSystem.Net.Http.Headers;namespaceapplicationui{ Public Partial classFileuploadform:form { PublicFileuploadform () {InitializeComponent (); }         Public voidUpload () {using(varClient =NewHttpClient ())using(varContent =Newmultipartformdatacontent ()) {client. baseaddress = new Uri ("http://wuznt016/flexpsappapi/");                varFile =@"D:\mail\marathon.txt"; varFilecontent =Newbytearraycontent (File.readallbytes (File)); FileContent.Headers.ContentDisposition=NewContentdispositionheadervalue ("Attachment") {FileName="Marathon.txt"                }; Content.                ADD (filecontent); varresult = client. Postasync ("Api/upload/post", content).                Result; Console.WriteLine (Result.            StatusCode); }        }        Private voidBtnupload_click (Objectsender, EventArgs e)        {Upload (); }    }}

Ionic app upload Image Webapi interface

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.