-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 André,
On 4/7/2009 5:56 PM, André Warnier wrote: > 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 ? Of course you can. Haven't we been over this one already? ;) > 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. ...especially because the servlet spec says that it will only decode form parameters if the content-type is application/x-www-form-urlencoded. If you use multipart/form-data, then your servlet has to read the entire request body using request.getReader() or request.getInputStream() and parse-out its own parameters AND file content. > Or else HttpRequest.getInputStream(), which returns a byte stream. But > then I guess I have to do the whole multipart/form-data parsing myself. Exactly. There are libraries that can handle this sort of stuff for you, but it's not part of the standard servlet API. Think of this as HTTP::multipart which you have to download from JPAN and install. :) > 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 ) ? There are several. Struts 2 has one built-into itself, as do other application frameworks. Here are several standalone ones: Super old-skool, still maintained: http://www.servlets.com/cos/index.html Newer, and probably more widely used: http://commons.apache.org/fileupload/ I'm sure there are others. IMO there's no reason to look beyond commons-fileupload. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAknbz3UACgkQ9CaO5/Lv0PCtFQCeOqQnQUBeD3mpb6ZQlxKu1SrU qo0AoLXQGCqMHT6ejyHr9O4xTmwZgtSF =II8q -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org