6

We have a requirement to upload images using ServiceStack APIs.

I am aware of two possible ways:

1) Use JSON object to upload file (Using BASE64 string). 2) Use "multipart/form-data"

Is there any other way of uploading files using ServiceStack? Which is better in terms of best practices?

Black-Baba
  • 83
  • 1
  • 7

1 Answers1

13

The best way to upload files in ServiceStack is to just do a normal HTTP File upload see the source code for imgur.servicestack.net or file uploads in RestFiles for examples.

If you don't want to send multipart/form-data then use a binary format like Protocol Buffers support in ServiceStack and send byte[] to avoid the computational and payload overhead of encoding binary files in a text format.

mythz
  • 141,670
  • 29
  • 246
  • 390
  • I like protocol buffers. Can it be easily implemented by various mobile clients? I am looking for a solution that can be consumed by variety of mobile apps without much struggle for developers. – Black-Baba May 13 '13 at 00:34
  • @Black-Baba Use `multipart/form-data` for the best interoperability as it will allow any HTTP Client on any platform that supports it to be able to upload files to your service. – mythz May 13 '13 at 03:43