0

In order to achieve a streaming upload I have written a custom PartHandler (Thread here ).

I now need to access a value that is stored inside the play! session inside the PartHandler. How can I do that ?

Code sample:

 def uploadFile() = 

    Action( parse.multipartFormData(myPartHandler) ) 
      {  request => 
           request.session.get("myValue") // <-- Recovering value is fine here
           Ok("Done") }

    def myPartHandler: BodyParsers.parse.Multipart.PartHandler[MultipartFormData.FilePart[Result]] = {
      parse.Multipart.handleFilePart {

        case parse.Multipart.FileInfo(partName, filename, contentType) =>

         // ** Need to access a value in session here **
         //request.session.get("myValue")...

        // Handle part ...

Thanks!

Community
  • 1
  • 1
Davz
  • 1,530
  • 11
  • 24

1 Answers1

0

With the help of other users of the play! framework google group, here is how to access the request inside a custom partHandler.

//Create a body parser
val myBodyParser = BodyParser { request => 
    parse.multipartFormData(myPartHandler(request)).apply(request)
}

 def uploadFile() = Action(myBodyParser) 
      {request =>Ok("Done")}

 def myPartHandler(request: RequestHeader) : BodyParsers.parse.Multipart.PartHandler[MultipartFormData.FilePart[Result]] = {
    parse.Multipart.handleFilePart {
      case parse.Multipart.FileInfo(partName, filename, contentType) =>         
        println(request.session.get("myValueKey"));
Davz
  • 1,530
  • 11
  • 24