Uploading image to WCF Api with RestSharp - Image is invalid

I have successfully made an application that sends a request from my Windows Phone to a WCF api hosted in an azure web role. I use the sedative POST method for this using RestSharp. All this works brilliantly and the images appear in the repository, but the images do not open like regular image files.

Comparing them with other images that I downloaded earlier, the metadata information says that the unenviable images have a contentMD5 field that is set to something like "AKEYWqGgulwi6 / 9 / VY2KPg ==" (while others don't) Is it what causes the file problem?

I have attached my RestSharp code, maybe I am adding something that I should not be? The error I suspect should come from here, as this is the only place where imagestream manipulates.

   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<VizageResponse>(request, response =>
            {
                //request info. to be added here
            });
    }

EDIT # 1 After some work, I decided to change the addFile line to this:

  request.AddFile(null, byteArray, null);

Which changed the length of the stream, and also made the contentMD5 field empty. However, the image is still not a valid image file. Considering the fact that the images I'm comparing are similar to Windows Phone emulators, they should be the same white page with a small black square in the corner, but there is a different size between the file (length 5670 for a valid image file, Length 6076 for source code and length 6239 using the second addFile above)

# 2 , Stream 6116, , 6370. 264 - RestSharp, , . WCF:

  [WebInvoke(UriTemplate = "/agerecog/{imageName}", Method = "POST")]
    VizageResult analyseFace(string imageName, Stream imageStream);
+3
2

, . , imageStream , ( Azure), .

MultipartParser, : http://multipartparser.codeplex.com/ , , [], .

webrequest :

    MemoryStream imageStream = new MemoryStream();

     MultipartParser parser = new MultipartParser(dataStream);
        if (parser != null && parser.Success)
        {
            imageName = parser.Filename;
            imageStream.Write(parser.FileContents, 0, parser.FileContents.Length);
        }

, , 0 - , !

+3

RestSharp. , MD5 ? blob . , , , / ( , ).

0
source

All Articles