'Looking for ideas for Multipart Form Handling on Web Service
I'm playing around with writing a web service that runs on Android that handles uploading photos. I am only writing the server, and do not have any control over the client.
Inside of the message is a small SOAP message, and then the binary data. I am trying to figure out if there's a library that can do the parsing of the two pieces. Apache Commons FileUpload looked like the obvious choice, however, it seems to be heavily intertwined with servlet libraries, and I don't know if it's possible (or if it's a good idea) to put too much J2EE infrastructure on a phone.
Parsing it myself doesn't seem too bad. I'm not too familiar with the raw HTTP layers/protocol, but it looks like the the boundary delimiter string is given in the content type header. If I find and index past those, I should be able to find the two halves of the multi-part message that I need to deal with. At least that's what I seem to think after looking at a wireshark trace of the client talking to the real server.
Solution 1:[1]
Although not exactly answering your question, I'm pretty confused to why you are trying to do this. You say you don't have any control over the client, yet you are trying to write a client-resident http server with multipart form handling. How would the client know to connect to this http server, vs one hosted somewhere else?
On android, IIRC, you have access to photos captured by the camera. So why would you want to transfer them over http from a local client to a local server? Basically, this seems insane.
From recently looking at multipart form handling in java, it's (a) in a sad state, (b) the open source options have lots of large third-party dependencies, and (c) it's way more complex than what you need for single file at a time uploading.
I realize this doesn't answer your question, but it will be easier with some more context on what you are trying to accomplish.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Noah |