Stephen Brannan - 423 - Jul 19, 2014

What’s the best way to upload a file to ServiceStack using angularjs (in my case I’m using the angular-file-upload module, which uses the html5 File API/FileReader). I was able to get it to upload to the service using the IRequiresRequestStream interface but it seems to include header information in the stream. Is there a better way to handle this? Or server side utils/methods to parse the content?

Here is a sample of the content I receive…

Content-Disposition: form-data; name=“file”; filename="test.txt"
Content-Type: text/plain

this is a test.

You can handle situations when what’s being POST’ed in the Request Body is not a DTO. E.g. you can post a raw file (e.g image) as a raw stream instead of being encoded in multi-part/form-data.

For multi-part form-data file uploads you can just use the Request.Files API, there’s an example on HttpBenchmarks:
And the ImageResizer example apps:

Stephen Brannan:

Ok I’ll give that a try. thanks.

Stephen Brannan:

Oh perfect! This worked great! Thanks so much! As always you provide top notch help and support!

Out of curiosity what situations is a IRequiresRequestStream useful?

It tells SS to skip normal Request DTO deserialization so you can do read from the body yourself, mentioned at:

Stephen Brannan:

Yeah I saw the docs on it. I was just wondering what use cases for it.