mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
37 lines
920 B
Scala
37 lines
920 B
Scala
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) = {
|
|
|
|
}
|
|
}
|
|
|