Featured post
java - Sending multiple files to a servlet with a single connection -
i'm writing java desktop client send multiple files on wire servlet using post request. in servlet i'm getting input stream request receive files. servlet write files disk, 1 one they're read stream.
the implementation has couple of requirements:
- only 1 http request must used server (so single stream)
- the servlet must use reasonable fixed amount of memory, no matter size of files.
i had considered inserting markers stream know when 1 file ends , next 1 begins. i'd write code parse stream in servlet, , start writing next file appropriate.
here's thing... surely there's library that. i've looked through apache commons , found nothing. commons file upload interesting since upload comes java app, not browser solves receiving end, not sending.
any ideas library allows multiple file transfers across single stream fixed memory expectations large files?
thanks.
just use http multipart/form-data
encoding on post request body. it's described in rfc-2388 , standard way of uploading (multiple) files http.
you can java.net.urlconnection
described in mini-tutorial, although generate lot of boilerplate code. more convenienced approach using apache commons httpclient.
in servlet side can use apache commons fileupload process uploaded files usual http way (or when you're on servlet 3.0, httpservletrequest#getparts()
, see this answer examples).
- Get link
- X
- Other Apps
Comments
Post a Comment