I have a Api Post method that I want to be able to accept any file type and that looks like this:
[HttpPost]
public async Task Post(
The MultipartFormDataContent
from the System.Net.Http
namespace will allow you to post multipart form data.
private async Task PostAttachment(byte[] data, Uri url, string contentType)
{
HttpContent content = new ByteArrayContent(data);
content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
using (var form = new MultipartFormDataContent())
{
form.Add(content);
using(var client = new HttpClient())
{
var response = await client.PostAsync(url, form);
return await response.Content.ReadAsStringAsync();
}
}
}