diff --git a/src/main/scala/ScalatraBootstrap.scala b/src/main/scala/ScalatraBootstrap.scala index d76150b..f84c99c 100644 --- a/src/main/scala/ScalatraBootstrap.scala +++ b/src/main/scala/ScalatraBootstrap.scala @@ -5,6 +5,7 @@ class ScalatraBootstrap extends LifeCycle { override def init(context: ServletContext) { context.mount(new IndexController, "/") + context.mount(new FileUploadController, "/upload") context.mount(new SignInController, "/*") context.mount(new UserManagementController, "/*") context.mount(new SystemSettingsController, "/*") diff --git a/src/main/scala/app/FileUploadController.scala b/src/main/scala/app/FileUploadController.scala new file mode 100644 index 0000000..f3e3ed9 --- /dev/null +++ b/src/main/scala/app/FileUploadController.scala @@ -0,0 +1,36 @@ +package app + +import org.scalatra._ +import org.scalatra.servlet.{MultipartConfig, FileUploadSupport} + +/** + * Provides Ajax based file upload functionality. + * + * This servlet saves uploaded file as temporary file and returns the unique key. + * You can get uploaded file using [[app.FileUploadUtil#getFile()]] with this key. + */ +// TODO Remove temporary files at session timeout by session listener. +class FileUploadController extends ScalatraServlet with FileUploadSupport with FlashMapSupport { + configureMultipartHandling(MultipartConfig(maxFileSize = Some(3*1024*1024))) + + post("/"){ + fileParams.get("file") match { + // TODO save as temporary file and return key. + case Some(file) => { + println(file.name) + println(file.size) + Ok("1234") + } + case None => BadRequest + } + } + +} + +// TODO Not implemented yet. +object FileUploadUtil { + def getFile(key: String) = { + + } +} + diff --git a/src/main/twirl/account/edit.scala.html b/src/main/twirl/account/edit.scala.html index 23bbbb4..36aa731 100644 --- a/src/main/twirl/account/edit.scala.html +++ b/src/main/twirl/account/edit.scala.html @@ -35,6 +35,13 @@
+ } + + \ No newline at end of file