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 Request entity too large
my js code for the upload is:
$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 =>
...
}
The default is 10MB for multipart form data, which you can also override by changing the play.http.parser.maxDiskBuffer
setting. See the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With