I have a ajax method for uploading file to server . - It sends the ArrayBuffer (Typed array of js from reading a file) to server with 3 more params. Endpoint is written in C# web API application.
Here is my C# endpoint -
public async Task<HttpResponseMessage> UploadFile(string param1, string param2, string fileName, [FromBody] byte[] arrayBuffer)
{
try
{
var response = await xyz.UploadFile(param1, param2, fileName, arrayBuffer);
var httpResponse = Request.CreateResponse(HttpStatusCode.Created);
httpResponse.Content = new StringContent(response, Encoding.UTF8, "application/json");
return httpResponse;
}
catch (Exception e)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, e.ToString());
}
}
My Question is what should be the type of the arrayBuffer param here in C# so that it get's populated with the binary data I sent in request from js.
Same request sent to Sharepoint's Rest API creates the file, I have already checked request is correct. Only problem is My endpoint is not able to match the data sent in RequestBody to it's param.
EDIT
For now we have changed the content to base64 string. Couldn't work on trying new things as we had to deliver. If anyone comes here with same problem Probably you will also have to do the same.
multipart/form-data
? – Eusebioeusebius