FIle Uploads on tomcat

3,328 views
Skip to first unread message

tom

unread,
Feb 15, 2015, 4:06:34 AM2/15/15
to spar...@googlegroups.com

I am developing locally on jetty and deploy it later to a tomcat. which works fine, except file uploads fail.

Uploading files works on jetty without problems, but on tomcat request.raw().getPart("file") always returns null.



MultipartConfigElement multipartConfigElement = new MultipartConfigElement(somepath);
request.raw().setAttribute("org.eclipse.multipartConfig", multipartConfigElement);
Part file = request.raw().getPart("file");

i configured my web.xml as in the example on the website.
i added the multipart-config element, but it changes nothing.

does anyone has any idea how i get this to work ? 
Maybe the problem is, that the app is running as a filter ? 

thank you 

Micheal Swiggs

unread,
Feb 16, 2015, 3:51:24 AM2/16/15
to spar...@googlegroups.com
Hi,

In addition to that link this is what I added:

<form method="post" enctype="multipart/form-data" action="/uploadimage">
   
<input type="file" name="image">
</form>




Part someImage = request.raw().getPart("image");

Micheal Swiggs

unread,
Feb 16, 2015, 7:19:36 AM2/16/15
to spar...@googlegroups.com

Sorry Tom, my response probably doesn't help you at all as I misread your post! :)


On Sunday, February 15, 2015 at 10:06:34 AM UTC+1, tom wrote:

Micheal Swiggs

unread,
Feb 16, 2015, 3:11:37 PM2/16/15
to spar...@googlegroups.com

I had the same problem. Eventually found it was a problem with tomcat. Need to set allowCasualMultipartParsing="true".  So in tomcat's context.xml set


<Context allowCasualMultipartParsing="true">



More info here:

https://stackoverflow.com/questions/8047173/how-to-enable-multipart-form-data-in-tomcat-7-0-8-server
http://www.coderanch.com/t/580782/Servlets/java/request-getPart-Tomcat


On Sunday, February 15, 2015 at 10:06:34 AM UTC+1, tom wrote:

tom

unread,
Feb 18, 2015, 4:09:17 PM2/18/15
to spar...@googlegroups.com
hey micheal, thank you so much, this worked ! 
can't understand my massive goggling did not bring up that page. ;)

thank you :D

Micheal Swiggs

unread,
Feb 23, 2015, 5:33:52 AM2/23/15
to spar...@googlegroups.com

No problems! :)
Reply all
Reply to author
Forward
0 new messages