Last active
December 14, 2015 10:29
-
-
Save reyman/5072477 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyRepoServlet(val system: ActorSystem) extends ScalatraServlet with ScalateSupport with FileUploadSupport with FutureSupport with SlickSupport { | |
configureMultipartHandling(MultipartConfig(maxFileSize = Some(3 * 1024 * 1024), fileSizeThreshold = Some(1024 * 1024 * 1024))) | |
protected implicit def executor: ExecutionContext = system.dispatcher | |
def processFile(upload: FileItem) = { | |
val filePath: String = "/tmp/" | |
println(">> " + upload.getName) | |
try { | |
val file: File = new File(filePath + upload.getName) | |
upload.write(file) | |
} catch { | |
case e: IOException ⇒ println("Error " + e) | |
} | |
} | |
get("/uploadMole") { | |
contentType = "text/html" | |
new AsyncResult() { | |
val is = Future { | |
ssp("/uploadMole", "body" -> "Please upload an om file below!") | |
} | |
} | |
} | |
post("/uploadMole") { | |
contentType = "text/html" | |
val x = new AsyncResult() { | |
val is = Future { | |
try { | |
val document: FileItem = fileParams("file") | |
println("file name: " + document.name) | |
processFile(document) | |
} catch { | |
case e: IOException ⇒ println("IO Error " + e) | |
case s: SecurityException ⇒ println("Security Error " + s) | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form name="data" action="/uploadMole" method="POST" enctype="multipart/form-data"> | |
<input type="File" name="file"><br> | |
<input type="Submit"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment