Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

André,

On 4/7/2009 4:49 PM, André Warnier wrote:
Ok Mark, I don't pretend I know how it works in Tomcat.
How does one upload a file then ?

That depends on how you /want/ to upload it. If you want to use the
standard HTML form-based file upload, you'll have to use
multipart/form-data (since that's what the HTML spec says to do).

PUT is, as stated, also an option.

The only real difference is the meaning of the target URI.

I mean other than with a PUT, as I presume that the OP doesn't just want
to write files arbitrarily in his URI space on the server)

If your server is expecting a single file for upload, then there is no
need to go through the whole multipart/form-data thing. You can just use
the Content-Type header to indicate that the file is
application/x-msword or whatever and jam the file into the request body.

multipart/form-data is only useful if you want both discrete data (like
form parameters) plus something huge, like the contents of a file. It's
just like an email message: there's no reason to use a multipart MIME
message when there's only one part to transmit.

Ok, got it, thanks Chris (and Mark).
Now suppose I /do/ a POST with multipart/form-data encoding to a Tomcat servlet, and one of the parts /is/ a large file.
How can I handle this at the servlet level ?
All I see in the Servlet Spec is HttpRequest.getParameter(), which returns a string (already URL-decoded), which seems hardly appropriate for uploading a file. Or else HttpRequest.getInputStream(), which returns a byte stream. But then I guess I have to do the whole multipart/form-data parsing myself.

Does there exist a library somewhere which allows me to feed it this InputStream and which will parse the parts for me appropriately (for example allowing me to determine if a given parameter is a file, and handle it easily ) ?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to