Description
- Framework version: 1.3.1
- Implementations: Core
Scenario
Multipart file uploads come through with the field name and filename inverted when retrieved from a Part obtained from the servlet request, compared to POSTing directly to an application running locally and not in lambda under aws-serverless-java-container, i.e. the behavior is inconsistent with tomcat and jetty.
This even stands out when you look at the two lines of code - the way the variables are names makes it clear their assignment has been swapped.
Expected behavior
Part should be received with name
set to the form field name and submittedFileName
containing the name of the file attachment.
Actual behavior
Part is received with name
set to the file attachment name and submittedFileName
set to the form field name, the inverse of what is expected.
Steps to reproduce
Using a rest client like POSTMAN, attempt to upload a file input into a POST API; for example submit a file named "sample-image.jpg" into a form field named "image". The results will come through inverted. Here is sample debug logging code for the handler:
Collection<Part> parts = httpServletRequest.getParts();
List<Map> partDesc=null;
if(parts!=null) {
partDesc = new ArrayList<>();
for(Part part: parts) {
Map pd = new HashMap<>();
pd.put("name", part.getName());
pd.put("size", part.getSize());
pd.put("type", part.getContentType());
pd.put("filename", part.getSubmittedFileName());
partDesc.add(pd);
}
}
Map details = new HashMap();
details.put("method", httpServletRequest.getMethod());
details.put("contentType", httpServletRequest.getContentType());
details.put("servletPath", httpServletRequest.getServletPath());
details.put("contextPath", httpServletRequest.getContextPath());
details.put("pathInfo", httpServletRequest.getPathInfo());
details.put("parts", partDesc);
log.info("Handling request for "+details);
Full log output
INFO: Handling request for {method=POST, servletPath=, contextPath=, parts=[{filename=image, size=257753, name=sample-image.jpg, type=image/jpeg}], contentType=multipart/form-data; boundary=--------------------------788920253325468350269863; charset=ISO-8859-1, pathInfo=/data/image}