Pawel Os.
Pawel Os.

Reputation: 633

Spring Boot, Jetty: Multipart upload - make Spring/Jetty accept body parts with missing "filename" attribute?

How to make Spring (or Jetty) accept/parse Multipart uploads where the body part(s) miss(es) the filename attribute in the Content-Disposition?

Otherwise than the missing filename attribute, the Multipart message is OK and it also used to work with an older version of Jetty/Spring.

What do I need to set to make Jetty/Spring a little more error tolerant again?

P.S. Here I found a similar yet different problem (name attribute missing). Yet, while the name seems like a vital attribute to identify body parts, you do not necessarily need the original client-side filename: Spring POST multipart/form-data Request empty body, getParts always empty

Upvotes: 0

Views: 554

Answers (1)

Pawel Os.
Pawel Os.

Reputation: 633

As already mentioned in the comment:

Spring (4.3.8.RELEASE) unconditionally skips multipart files without a filename, i.e. there is no setting to make it more error-tolerant. Thus, the only solution was to override Spring's StandardMultipartHttpServletRequest class and modify the method in question: parseRequest.

The added lines of code:

if (filename == null && "file".equalsIgnoreCase(part.getName()) && MediaType.APPLICATION_OCTET_STREAM.equalsIgnoreCase(part.getContentType())) {
    filename = DEFAULT_FILENAME;
}

And yes, the name of the multipart body part doesn't necessarily have to be "file" but this is the name the client application my code has to work with is using when uploading a file.

Upvotes: 0

Related Questions