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