{ "code": 500, "message": "Required part 'file' is not present.", "result": null, "type": "error" }
On behalf of the servlet request body in fact, there is no such file stream parameters, with the file name and parameter name does not have much to do, and file upload springboot is the default open, do not need to show to open the
# Data source configuration servlet. multipart. enabled.true max-file-size: 20MB max-request-size: 20MB
After that, we have been based on this error message to find the relevant documents, and found that there are many reasons for this problem, then one by one to troubleshooting
1. Inconsistent correspondence between front and back-end parameter names
=false disables file upload support
3. Configuration file specified in the file upload when the size of the value of the problem
4. switch the embedded container tomcat to undertow configuration issues
= /tmp specifies a temporary file station, but the path does not exist
6. Read the HttpServletRequest stream multiple times
Already have CommonsMultipartResolver, need to exclude original Multipart configuration @EnableAutoConfiguration(exclude = {})
After troubleshooting one by one, I realized that I had been used multiple times before the request body got to the interface, which fits well with the problem of reading the HttpServletRequest stream multiple times
This is the place to use it:
import ; import ; import ; import ; /** * CachedBodyHttpServletRequest extends the HttpServletRequestWrapper class. * * Used to cache the request body so that it can be read multiple times. */ public class CachedBodyHttpServletRequest extends HttpServletRequestWrapper { private final byte[] cachedBody; /** * Constructor that reads the request body and caches it. * * @param request The original HttpServletRequest. * @throws IOException If an I/O error occurs */ public CachedBodyHttpServletRequest(HttpServletRequest request) throws IOException { super(request); // Reads the request body and converts it to a byte array InputStream requestInputStream = (); this.cachedBody = (); }