Julien
Julien

Reputation: 3529

Upload image with RESTSharp (addFile)

I'd like to send a picture from my Windows Phone on a webservice hosted on Windows Azure. To communicate with my service, I use RESTSharp and I saw that there was a method named addFile for sending file.

RestRequest request;
request = new RestRequest("/report/add", Method.POST);

request.AddFile("test", ConvertToBytes(e.ChosenPhoto), "testfile");
App.Client.ExecuteAsync(request, response =>
{
    RestResponse resource = response;
    if (response.StatusCode == HttpStatusCode.OK)
    {
        MessageBox.Show("Your report has been sent! Thank you for your participation!");
    }
});

However, I do not know how to retrieve the array of bytes sent when the request arrives at the service. Can you help me please?

Upvotes: 4

Views: 5234

Answers (1)

Sandrino Di Mattia
Sandrino Di Mattia

Reputation: 24895

Could you show the code that you use to handle the file server side? It could be that you're looking in the wrong place.

Alternatively, you could try an other way to add the file:

request.AddBody(new { myFile = fileByteArray }))

Note: In both cases the file will be loaded in memory. This could be a problem for large files.

Upvotes: 1

Related Questions