Answer the question
In order to leave comments, you need to log in
How to get byte[] passed from client in asp.net 5 web api controller?
I want to pass a byte[] and a string to the controller. For this I use MultipartFormDataContent. But I can't get the transferred array of bytes in the controller. In this case, the string can be obtained.
Client code:
public static void UploadFile()
{
Uri uploadEndpoint = new Uri("http://localhost:56010/api/values");
var content = new MultipartFormDataContent();
content.Add(new StringContent("any string"), "anystring");
var fileContent = new ByteArrayContent(new byte[]{3,3,3,3});
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("anybytes")
{
FileName = "Foo.txt"
};
content.Add(fileContent);
var client = new HttpClient();
HttpResponseMessage hrm = client.PostAsync(uploadEndpoint, content).Result;
}
[HttpPost]
public IActionResult PostFile(byte[] anybytes)
{
//здесь anybytes == null, а должен быть переданный массив
return new HttpOkResult();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question