java Spring Rest API 最大大小 HTTP POST

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28286905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:20:22  来源:igfitidea点击:

Spring Rest API maximum size HTTP POST

javaspringrest

提问by Vinchenzo

I currently have a Java Spring Rest API that enables images base64 to be uploaded to my server. Now I would like to know if there is a way I can limit the upload size so that people wont be able to upload 1GB and crash my server.

我目前有一个 Java Spring Rest API,可以将 base64 图像上传到我的服务器。现在我想知道是否有办法限制上传大小,这样人们就无法上传 1GB 并使我的服务器崩溃。

回答by David Riccitelli

For those using Spring Boot, consider setting the following parameters in your application.properties(or application.yml) file:

对于使用 Spring Boot 的用户,请考虑在application.properties(或application.yml)文件中设置以下参数:

multipart.max-file-size=1Mb
multipart.max-request-size=10Mb

See Common application properties.

请参阅通用应用程序属性

回答by Juned Ahsan

I believe it should be configured on the web server level and not on the code level. For example in tomcat you can configure maxPostSizeparam present in server.xml to limit the size of Http POST request.

我相信它应该在 Web 服务器级别而不是代码级别进行配置。例如在 tomcat 中,您可以配置maxPostSizeserver.xml 中的参数来限制 Http POST 请求的大小。