0

When a file is submitted to my server using a multipart/form-data POST, is it possible to retrieve only the content of the file from the HttpServletRequest object? The request.getInputStream() shows some headers included at the beginning and then ------WebKitFormBoundary... at the end.

Can I get just the file data without having to parse the input stream and extract it?

RTF
  • 6,214
  • 12
  • 64
  • 132

1 Answers1

2

You could annotate your servlet with @MultipartConfig, then you can use HttpServletRequest#getParts() to get the individual parts.

This is available starting from Servlet 3.0. If for some reason you're stuck on an older version of Java Servlets, you may choose to use Apache Commons File Upload.

Frans van Buul
  • 3,009
  • 1
  • 13
  • 6
  • Thanks, sounds perfect, but em... eclipse is telling me that `HttpServletRequest` does not have a function called `getParts()` - I guess I need to be using a different version of Java. BTW, I'm using the Google App Engine. – RTF Apr 27 '14 at 14:14
  • I got everything working with additional help from this question: http://stackoverflow.com/questions/5742684/using-apache-fileupload-on-gae – RTF Apr 27 '14 at 14:47