jack miao jack miao - 1 year ago 436
AngularJS Question

How to fix 413 HTTP Request entity too large

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];
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)
val j = Json.parse( ${Crypto.encryptAES(localFile.getAbsolutePath)}})

what needs to be change in order to support bigger files?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download