2

What is the general approach to exposing a REST based web service that can accept a base64 encoded image. I'm not sure yet if the image will be an InputStream or a ByteArray. I'm using RESTEasy. Can I just map this as a @FormParam (javax.ws.rs.FormParam)? What is the usual data type for the incoming image?

dur
  • 15,689
  • 25
  • 79
  • 125
c12
  • 9,557
  • 48
  • 157
  • 253

1 Answers1

2

First off, you want to receive the image as an InputStream because they can be quite large. (I have a digital camera that produces a 12 megapixel image. It's not the latest model. The images it produces are quite a few megabytes even when stored as JPEGs. You don't want to get that sort of data cluttering up memory more than necessary.)

Secondly, you can make your web service accept raw unencoded data as upload. It's actually easier than taking base-64 encoded data (provided you're pulling it as a stream) and it's a good saving of system bandwidth and processing. If you're wanting to send other data at the same time, you should consider dealing with multipart content. (Alas, I've no experience with that part; haven't needed it for the RESTful webservices I've been working on.)

Thirdly, images should be described as a content type in the image/* space, but double check in practice to see if that's what you really get. When serving them up back to clients, you must send it back as one of the image/* set.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215