Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading image to WCF Api with RestSharp - Image not valid
    primarykey
    data
    text
    <p>I have successfully made an app that sends a request from my Windows Phone to a WCF api hosted in an azure web role. I am using a restful POST method to do this using RestSharp. It all works brilliantly and the images are appearing in storage but the images are not opening as normal image files.</p> <p>Comparing them to other images I uploaded previously, in the metadata info it says the unviewable images have a contentMD5 field which is set to something like "AKEYWqGgulwi6/9/VY2KPg==" (whereas the others do not) could this be what is causing the problem with the files?</p> <p>I have attached my RestSharp code, maybe I'm am adding something I shouldn't be? The error I suspect must be coming from here as this is the only place where the imagestream is manipulated.</p> <pre><code> public void SendRequest(Stream imageStream, string imageID) { var client = new RestClient(); client.BaseUrl = apiAddress; var request = new RestRequest("agerecog/{imageName}", Method.POST); request.AddUrlSegment("imageName", imageID); //convert imagestream to byte array var byteArray = new byte[imageStream.Length]; imageStream.Read(byteArray, 0, (int)imageStream.Length); //add byteArray to request request.AddFile("image/jpeg", byteArray, imageID); var url = client.BuildUri(request).ToString(); client.ExecuteAsync&lt;VizageResponse&gt;(request, response =&gt; { //request info. to be added here }); } </code></pre> <p><strong>EDIT #1</strong> After some work I decided to change the addFile line to this:</p> <pre><code> request.AddFile(null, byteArray, null); </code></pre> <p>Which changed the stream length and also made the contentMD5 field empty. However, the image is still not a valid image file. Given the fact the images I am comparing are both from the Windows Phone emulator they should both be an identical white page with a small black square in the corner - but there is a different in size between the file (5670 length for the valid image file, 6076 length for the original code and 6239 length using the second addFile above)</p> <p><strong>EDIT #2</strong> Doing some more analysis, when the before the image Stream is sent its length property is 6116, when it arrives on the server, however it is 6370. 264 is being added from somewhere in the RestSharp method I believe or when the stream of data is interpreted on the server side. The code of the WCF service:</p> <pre><code> [WebInvoke(UriTemplate = "/agerecog/{imageName}", Method = "POST")] VizageResult analyseFace(string imageName, Stream imageStream); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload