RTF
RTF

Reputation: 6494

Can I get the HttpServletRequest request body without headers?

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?

Upvotes: 0

Views: 2684

Answers (1)

Frans van Buul
Frans van Buul

Reputation: 3289

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.

Upvotes: 2

Related Questions