I'm trying to upload a file using Scalatra Version: 2.4.0.
The file I'm trying to upload is only 181 bytes, but I keep getting my file size too large error message, but it's not too large. Everything is compiling and IntelliJ is showing no errors. When I upload, it shows the error page I'm expecting that says "File size too large!".
I've set up the MultipartConfig according to the Scalatra guide found here: Scalatra File Upload.
Right now I'm just trying to get the upload working so I'm just printing to the console, I'll be working with the file in the request.
What am I missing here?
Form
<form action="/upload" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="btn btn-primary" for="file-selector">
<input id="file-selector" name="the-file" type="file" style="display:none;" onchange="$('#upload-file-info').html($(this).val());" />
Choose File
</label>
<span class='label label-info' id="upload-file-info"></span>
</div>
<button type="submit" class="btn btn-primary">Upload</button>
</form>
Servlet
trait UploadServlet extends BaseServlet with FileUploadSupport {
error {
case e:
SizeConstraintExceededException => {
RequestEntityTooLarge("File size too large!")
}
post("/upload") {
Console.println("Yo Yo Ma")
}
}
Web App Launcher (WebappLauncher.scala)
myApp.webapp.servletsMap.foreach { case (path, servlet) =>
val holder = context.addServlet(servlet, path + "*")
holder.getRegistration.setMultipartConfig(
MultipartConfig(
maxFileSize = Some(5 * 1024 * 5000),
fileSizeThreshold = Some(5 * 1024 * 5000)).toMultipartConfigElement)
}