c# - Unable to get the entire Image in web Api while doing Post from the MVC controller? -
actually, sending image memory stream mvc controller web api memorystream, while downloading image in web api, getting half image instead of full image.please find sample output image in link
my mvc controller:
public actionresult index(formcollection formcollection) { foreach (string item in request.files) { httppostedfilebase file = request.files[item] httppostedfilebase; if (file.contentlength == 0) continue; if (file.contentlength > 0) { memorystream ms = new memorystream(); file.inputstream.copyto(ms); ms.position = 0; httpclient client = new httpclient(); client.baseaddress = new uri("http://localhost:35221"); client.defaultrequestheaders.accept.add(new system.net.http.headers.mediatypewithqualityheadervalue("application/octent-stream")); httpcontent content = new streamcontent(ms); var response = client.postasync("api/ocr/gettext",content).result; if (response.issuccessstatuscode) { }}}}
my web api controller:
[httppost] public list<string> gettext(httprequestmessage request) { try { httpcontent content = request.content; memorystream ms = new memorystream(); content.copytoasync(ms); stream stream = ms; bitmap bmp = new bitmap(stream); bmp.save(@"c:\users\bpopuri\desktop\test\temp.jpg"); byte[] value = memorystream.toarray(); }
sorry guys, unable post total code here. sending image mvc web api image in web api not loading properly.
please me how avoid problem.
thanks in advance
you'll need await
call copytoasync
. in order that, make following changes:
public async task<list<string>> gettext(httprequestmessage request) { ... await content.copytoasync(ms); ... }
it looks problem due copy operation not completing before attempt save file.
Comments
Post a Comment