azure - Image cut after being uploaded to webapi -


i use code upload images in asp.net webapi:

[httppost] [route("imagebrowser/insert")] [sharepointcontextwebapifilter] public object postfile() {     httprequestmessage request = this.request;     if (!request.content.ismimemultipartcontent())     {         throw new httpresponseexception(httpstatuscode.unsupportedmediatype);     }       string root = system.web.httpcontext.current.server.mappath("~/content/images");     var provider = new multipartformdatastreamprovider(root);     request.content.readasmultipartasync(provider);       //return request.createresponse(httpstatuscode.ok);      return request.createresponse(httpstatuscode.ok); } 

the file not being uploaded correctly, looks enter image description here

is related azure? there wrong code?

the problem because you're using async code in non async method. thread being finished before ending read part.

try this:

[httppost] [route("imagebrowser/insert")] [sharepointcontextwebapifilter] public async object postfile() {     httprequestmessage request = this.request;     if (!request.content.ismimemultipartcontent())     {         throw new httpresponseexception(httpstatuscode.unsupportedmediatype);     }       string root = system.web.httpcontext.current.server.mappath("~/content/images");     var provider = new multipartformdatastreamprovider(root);     await request.content.readasmultipartasync(provider);       //return request.createresponse(httpstatuscode.ok);      return request.createresponse(httpstatuscode.ok); } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -