+1 about what was mentioned above in Radim ... According to your action, binding the web API model, the fileContents parameter is a complex type and, by default, involves reading the contents of the request body using formatters. (note that since the fileName and description parameters are of type string , they are expected to come from uri by default).
To prevent model binding, you can do something like the following:
[HttpPost] [HostAuthentication(DefaultAuthenticationTypes.ExternalBearer)] [Route("UploadFile")] public async Task UploadFile(string fileName, string description) { byte[] fileContents = await Request.Content.ReadAsByteArrayAsync(); .... }
By the way, what do you plan to do with this fileContents ? Are you trying to create a local file? if so, is there a better way to handle this.
Update based on your last comment :
A quick example of what you could do
[HttpPost] [HostAuthentication(DefaultAuthenticationTypes.ExternalBearer)] [Route("UploadFile")] public async Task UploadFile(string fileName, string description) { Stream requestStream = await Request.Content.ReadAsStreamAsync();
Kiran challa
source share