2

Currently I have a "Post" action in my web API controller. I first attempted having a byte[] as the only argument, hoping it would "just work". Unfortunately, it did not and it complained about formatting and conversion for form-data.

Now I have attempted to read the file content with this.Request.Content, which others seem to have had success with. Unfortunately this is including more than I really want: The content disposition, the file name, the content type, and some kind of webkit form boundary. I assume it is all of the request content.

What is the right way to do this? I have found lots of answers for ASP .NET with the FileUpload control and many articles on how to upload to a .NET web API expecting a file via POST.

Some articles mention Request.Files but it is not part of the HttpRequestMessage class.

Michael J. Gray
  • 9,784
  • 6
  • 38
  • 67
  • 1
    Check this: http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2 – Kiran Jun 27 '13 at 22:11

1 Answers1

4

If you're talking about multipart form data, you should have a look at our official documentation:

http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2

Youssef Moussaoui
  • 12,187
  • 2
  • 41
  • 37
  • 1
    I don't know why this doesn't rank high in Google! I searched for "read file content asp.net web api post data" and it wasn't even on the first page. Thank you so much. – Michael J. Gray Jun 27 '13 at 22:58
  • @Youssef please do you think you could help me with this question http://stackoverflow.com/questions/24235617/asp-net-web-api-what-problems-could-arise-if-i-use-post-instead-of-put-and-del/24235652#24235652 – eddy Jun 16 '14 at 02:48
  • 1
    The link is broken – Mo Sadeghipour Apr 01 '21 at 10:17