3

I try to increase the max-content-length so that large files can be uploaded to the server.

I have added this to application.conf

spray.can {
  server {
    parsing {
      max-content-length = 2g
      max-chunk-size = 10m
    }
  }
}

However the cap seems to still be at 1MB. I can confirm that the parameters are read, as I can lower the cap and it will take effect.

The application triggers a response error (413 Request Entity Too Large), I have a HttpService (accepting CORS) and a route looking like this:

val contentRoute =
  cors {
    pathPrefix(PROJECTS) {
      (post & path(Segment / CONTENT)) { (projectId) =>
        post {
          entity(as[MultipartFormData]) { data =>
            complete(StatusCodes.OK)
          }
        }
      }
    }
  }

Could there be some other preference that I also need to adjust, that is also set to 1MB by default?

Update:

These are the dependency versions:

libraryDependencies ++= {
  val akkaV = "2.3.9"
  val sprayV = "1.3.3"
  Seq(
    "io.spray"            %%  "spray-can"     % sprayV,
    "io.spray"            %%  "spray-routing" % sprayV,
    "io.spray"            %%  "spray-json"    % "1.3.2",
    "io.spray"            %%  "spray-testkit" % sprayV  % "test",
    "com.typesafe.akka"   %%  "akka-actor"    % akkaV,
    "com.typesafe.akka"   %%  "akka-testkit"  % akkaV   % "test",
    "org.specs2"          %%  "specs2-core"   % "2.3.11" % "test",
    "org.mongodb"         %%  "casbah"        % "2.8.2"
  )
}
spydon
  • 9,372
  • 6
  • 33
  • 63
  • Possible duplicate of http://stackoverflow.com/questions/30025952/override-spray-can-property – Costi Ciudatu Dec 07 '15 at 17:32
  • He wants to change the properties on start of the application, I do not require that, I only use the normal application.conf. Therefore it is not a duplicate. – spydon Dec 07 '15 at 20:44
  • Seemingly his application.conf actually works too, which makes it even less of a duplicate. – spydon Dec 07 '15 at 20:50

1 Answers1

2

My bad, the configuration is correct and working. Hopefully other people with the same problem as this will stumble over this post.

The problem was not spray-can, but the nginx proxy in front of it. One obviously also have to modify the max-content-length limit in nginx too.

Which is done by putting the following in /etc/nginx/nginx.conf:

http {
    server {
        ...
        client_max_body_size 100M;
        ...
    }
}
spydon
  • 9,372
  • 6
  • 33
  • 63