开发者

post an image, with request parameters? [duplicate]

开发者 https://www.devze.com 2023-02-10 16:19 出处:网络
This question already has answers here: How can I upload files to a server using JSP/Servlet? (14 answers)
This question already has answers here: How can I upload files to a server using JSP/Servlet? (14 answers) Closed 1 year ago.

I am building a servlet that accepts an image in a POST reque开发者_如何学运维st. with each post there should be an associated ID. My question is how to pass these two distinct data values in a post, where one is a short string, and another is a large chunk of binary data.

I could have both as post parameters,

id=123
content=...megabytes of binary data...

but I need the flexibility of handling the content as a stream, as it could be quite large. I could also follow the above pattern by parsing the input myself as binary data, which I'd like to avoid. I guess I'd need to parse it character by character looking for the keys. ugly.

Am I missing the correct pattern for handling this?


The standard technique, used in browser to send form data containing both text and file inputs, is to use multi-part form data.

Apache commons FileUpdload could be used at server-side to parse the request, and give you access to the uploaded image as a stream.

0

精彩评论

暂无评论...
验证码 换一张
取 消