How to receive a POSTed image in a REST web service

百般思念 提交于 2019-12-06 22:01:41

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!