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
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
Post a Comment