[英]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? 当使用multipart / form-data POST将文件提交到我的服务器时,是否可以从HttpServletRequest对象中仅检索文件的内容? The request.getInputStream()
shows some headers included at the beginning and then ------WebKitFormBoundary...
at the end. request.getInputStream()
显示开头包含的一些头文件,然后是------WebKitFormBoundary...
最后。
Can I get just the file data without having to parse the input stream and extract it? 我是否可以只获取文件数据而无需解析输入流并将其解压缩?
You could annotate your servlet with @MultipartConfig , then you can use HttpServletRequest#getParts() to get the individual parts. 您可以使用@MultipartConfig注释您的servlet,然后您可以使用HttpServletRequest#getParts()来获取各个部分。
This is available starting from Servlet 3.0. 这是从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 . 如果由于某种原因你被困在旧版本的Java Servlets上,你可以选择使用Apache Commons File Upload 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.