Web API File Upload, Single or Multiple files

Software Engineering

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.

Code: https://github.com/damienbod/WebApiFileUpload

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s