如何修复413 HTTP请求实体太大 [英] How to fix 413 HTTP Request entity too large
问题描述
我有一个项目,其中有一个用angularjs编写的简单客户端,服务器在scala中,在我的客户端中,我有一个简单的上载按钮,您可以在其中单击并选择本地文件(csv),并在上载时某个较大的csv,例如我得到的6000行
I have a project where I have a simple client written in angularjs and the server is in scala, in my client I have a simple upload button where you click on it and choose a local file(csv), and when I upload a certain csv that is a bit big, like 6000 rows I get
413请求实体太大
413 Request entity too large
我上传的js代码是:
$scope.upload = function(files) {
if (!files || !files.length) {
} else {
for (var i = 0; i < files.length; i++) {
var file = files[i];
Upload.upload({
url: '/uploadFile',
file: file
}).
}).success(function (data, status, headers, config) {
}).error(function (data, status, headers, config) {
$scope.showServerError(status, data);
})
}
}
};
服务器中的
是:
in the server is :
def uploadFile = Action(parse.multipartFormData) { implicit request =>
request.body.file("file").fold {
BadRequest("Missing file")
} { uploadedFile => {
val localFile = new File("/tmp/" + uploadedFile.ref.file.getName)
Files.copy(uploadedFile.ref.file.toPath, localFile.toPath, StandardCopyOption.REPLACE_EXISTING)
localFile.deleteOnExit()
val j = Json.parse( ${Crypto.encryptAES(localFile.getAbsolutePath)}})
Ok(j)
}}
}
为了支持更大的文件,需要进行哪些更改?
what needs to be change in order to support bigger files?
推荐答案
You can use the maxLength
body parser to specify the maximum size of the body in bytes:
// Allow up to 15MB files...
private val uploadParser = parse.maxLength(15*1024*1024, parse.multipartFormData)
def uploadFile = Action(uploadParser) { implicit request =>
...
}
多部分表单数据的默认值为10MB,您也可以通过更改play.http.parser.maxDiskBuffer
设置来覆盖它.请参见文档.
The default is 10MB for multipart form data, which you can also override by changing the play.http.parser.maxDiskBuffer
setting. See the docs.
这篇关于如何修复413 HTTP请求实体太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!