Bohtvaroh

Unfiltered/Netty file upload

Oct 20th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.91 KB | None | 0 0
  1. package com.artezio.cv.http
  2.  
  3. import unfiltered.request._
  4. import unfiltered.response._
  5. import unfiltered.netty._
  6.  
  7. import unfiltered.netty.request._
  8.  
  9. object Main extends App {
  10.   Http(8080).chunked().handler(cycle.Planify {
  11.     case GET(Path("/")) =>
  12.       ResponseString(
  13.         """
  14.          |<form action="/upload" method="post" enctype="multipart/form-data">
  15.          |CV: <input type="file" name="f"/>
  16.          |<input type="submit" value="Submit"/>
  17.          |</form>
  18.        """.stripMargin)
  19.     case POST(Path("/upload") & MultiPart(req)) =>
  20.       val disk = MultiPartParams.Disk(req)
  21.       (disk.files("f"), disk.params("p")) match {
  22.         case (Seq(f, _*), p) =>
  23.           ResponseString(
  24.             "cycle disk read file f named %s with content type %s and param p %s" format(
  25.               f.name, f.contentType, p))
  26.         case _ => ResponseString("what's f?")
  27.       }
  28.   }).run()
  29. }
Advertisement
Add Comment
Please, Sign In to add comment