4
RestSharp를 통해 내 서버에 이미지를 업로드하는 데 문제가 있습니다.RestSharp 이미지를 WCF REST 서비스에 게시
스트림을 허용하는 Rest Wcf 서비스가 있습니다. 난 항상이 예외를 얻을 아래 내가 코드를 사용하는 경우 :
ProtocolViolationException 바이트 이 스트림에 기입 할
는 지정된 콘텐츠 길이 바이트 크기를 초과.
구성해야 할 설정은 무엇입니까 ... 콘텐츠 길이 헤더를 설정하면 아무런 효과가없는 것으로 보입니다.
서버 측은 이미지를 수신하지 않지만 더 작은 바이트 스트림을 수신합니다.
도움을 주시면 감사하겠습니다.
클라이언트 (테스트) 코드 :
byte[] byteArray = File.ReadAllBytes("small.jpg");
request.AddHeader("Content-Length", int.MaxValue.ToString());//doesn't matter what length I put here
request.AddFile("image/jpeg", (requestStream) =>
{
using (var ms = new MemoryStream(byteArray))
{
ms.CopyTo(requestStream, byteArray.Length);//doesn't matter whether I add second param or not
ms.Flush();
ms.Close();
}
},
"sample",
"image/jpeg");
request.Method = Method.POST;
client.ExecuteAsync(request, (response, a) =>
{
Assert.IsNotNull(response.Content);
string content = response.Content;
resetEvent.Set();
});
서비스 코드
[OperationContract]
[WebInvoke(UriTemplate = "upload/{fileName}/{fileExtension}/{id}", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
Message UploadPhoto(string fileName, String fileExtension, string id, Stream fileContents);
음 .. 아마도 파일이 너무 큽니까? –
바이트 배열을 취하는'AddFile()'오버로드를 사용해야합니다. –
* "어떤 대답이 가장 도움이되는지 결정한 경우 대답의 왼쪽에있는 확인란 개요를 클릭하여 허용되는 답변으로 표시하십시오."(From stackoverflow.com/faq#howtoask). 문제가 해결 되었다면 답을 표시하십시오! – DIF