This article demonstrates file uploads using Web API 2. The examples use the MultipartFormDataStreamProvider class. The controller implementation saves the files in memory first, so for large files or with a lot of HTTP traffic, this is not a good solution. Links to other examples are also included at the bottom of this post.
The Web API controller implements the server method for file upload. This saves the content to a provider location and creates a new file name with no endings. The file(s) information is collected from the form data and the file headers. The headers are not always set depending on the client. This server method works for both single and multiple file uploads.
The server method uses a ValidateMimeMultipartContentFilter attribute to check if the correct MIME type is sent. This can then be used for all uploads methods.
If the upload is successful, a FileResult…
View original post 202 more words