Skip to content

Instantly share code, notes, and snippets.

@vigack
Last active September 22, 2017 06:04
Show Gist options
  • Save vigack/d87185e3800297585a318d0093eabf7f to your computer and use it in GitHub Desktop.
Save vigack/d87185e3800297585a318d0093eabf7f to your computer and use it in GitHub Desktop.
spring的multipart/formdata 仅支持post请求

初次尝试REST规范,在使用PATCH,PUT的时候出现了问题,无法通过@RequestParam获取参数值 阅读源码,发现对于multipart/formdata形式的请求,spring都会做如下判断

public static final boolean isMultipartContent(
            HttpServletRequest request) {
        if (!POST_METHOD.equalsIgnoreCase(request.getMethod())) {
            return false;
        }
        return FileUploadBase.isMultipartContent(new ServletRequestContext(request));
    }
@vigack
Copy link
Author

vigack commented Sep 22, 2017

实际上客户端并不会限制patch或put方法的请求头,所以这不是技术问题而是规范问题,为什么spring不建议/支持这种方式传输文件呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment