我有一个项目,我有一个用 angularjs 编写的简单客户端,服务器在 scala 中,在我的客户端中,我有一个简单的上传按钮,您可以单击它并选择本地文件(csv),当我上传某个 csv 时这有点大,比如我得到的 6000 行
413请求实体太大
我的上传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);
})
}
}
};
在服务器中是:
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)
}}
}
为了支持更大的文件需要改变什么?
您可以使用maxLength https://www.playframework.com/documentation/2.5.x/api/scala/index.html#play.api.mvc.BodyParsers%24parse正文解析器指定正文的最大大小(以字节为单位):
// 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
环境。请参阅docs https://www.playframework.com/documentation/2.5.x/ScalaBodyParsers#Max-content-length.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)