Friday, March 29, 2013

Web API file upload set filename

By default when you upload files using ASP.NET Web API, the files are saved using a random filename.

WebApiFileUpload

This is not a bug, but a security decision Microsoft made. They considered it a security risk to take the file name provided in the Content-Disposition header field and decided  instead to compute a file name.

You can easily solve this by deriving from the default MultiPartFormDataStreamProvider and provide your own naming mechanism:

If you want to know some more about uploading files using Web API, I recommend the following blog post: A guide to asynchronous file uploads in ASP.NET Web API RTM

No comments: