bowler-framework / Bowler

RESTful Web Framework based on Scala, built on top of Scalatra & Scalate
http://bowlerframework.org
BSD 3-Clause "New" or "Revised" License
118 stars 13 forks source link

Uploading files that is smaller than 10kb #23

Open aslakjo opened 12 years ago

aslakjo commented 12 years ago

Hi

We have an issue with bowler and file uploads. It looks like files that are uploaded that are larger than 10kb is saved and there path is stored inside the StoreLocation "variable" of the string that comes into our action. With these large files the file is ok and can be read.

However if the file uploaded to Bowler is less than 10kb the path inside of StoreLocation is pointing to a file that does not exists. I there for get a FileNotFound exception.

The file that is uploaded should be properly saved to the path, and should be able to be read.

These are my versions; "org.bowlerframework" %% "core" % "0.5.1", "org.slf4j" % "slf4j-nop" % "1.6.0" % "runtime", "javax.servlet" % "servlet-api" % "2.5" % "provided", "org.eclipse.jetty" % "jetty-webapp" % "7.4.2.v20110526" % "container", "org.eclipse.jetty" % "jetty-webapp" % "7.4.2.v20110526", "org.scalatra" %% "scalatra-scalatest" % "2.1.0-SNAPSHOT" % "test", "org.specs2" % "specs2_2.9.0" % "1.3" % "test", "net.liftweb" %% "lift-json" % "2.3" % "test", "net.java.dev.jets3t" % "jets3t" % "0.8.1", "org.scala-tools.time" %% "time" % "0.5", "org.bowlerframework" %% "squeryl-mapper" % "0.5.1", "com.h2database" % "h2" % "1.2.144", "c3p0" % "c3p0" % "0.9.1.2", "org.squeryl" %% "squeryl" % "0.9.5-RC1", "postgresql" % "postgresql" % "8.4-701.jdbc4", "org.imgscalr" % "imgscalr-lib" % "4.1", "net.databinder" %% "dispatch-http" % "0.8.7"

aslakjo commented 12 years ago

I have now made an example to recreate the bug. You can find it here: https://github.com/aslakjo/10k-problem If you upload a small file it will say: "file exists on filesystem false " and if you upload a larger file it will say "file exists on filesystem true"

The true/false is from File.exists(). Our current theory is that this is related to small files not being written to disk and is only part of memory.

Hope this information helps in finding the bug.

aslakjo commented 12 years ago

It seems that there is some problem mapping from a FileUploadSupport.fileParams to a BowlerHttpRequest.params : Map[String, Any] results in the FileItem beeing stringifyed.

This means that in bowler the fileParams and fileMultiParams that contain FileItems will be converted to strings in mapExecutor of the class BowlerFilter. To be more spesific, it looks like the flatternParameter of BowlerHttpApplicationRouter changes from FileItem to String.

I am guesing that this might be a side effect of toMap or converting from a HashMap to a Map. I am working on a workaround to preserve the FileItem to be used inside my action. But the proper way is to preserve FileItems as FileItems and prevent them beeing converted to strings.