我想通过 Windows Azure 上托管的 Web 服务从我的 Windows Phone 发送图片。 为了与我的服务进行通信,我使用 RESTSharp,并且我看到有一个名为 addFile 的方法用于发送文件。
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!");
}
});
但是,我不知道如何检索请求到达服务时发送的字节数组。 你能帮我一下吗?
最佳答案
你能展示一下你用来处理文件服务器端的代码吗?您可能找错了地方。
或者,您可以尝试其他方式来添加文件:
request.AddBody(new { myFile = fileByteArray }))
注意:在这两种情况下,文件都会加载到内存中。对于大文件来说这可能是一个问题。
关于wcf - 使用 RESTSharp 上传图像(addFile),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10125174/