Accessing session information inside a custom PartHandler in Play! Framework 2.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!

Answers


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"));

Need Your Help

How to convert Readdata ,Writedata from mainDrive to separated Class in Java

java

I have Java program work correctly. Just I need to convert writeData and readData Methods from MainDrive to separated Class.

Replace all occurencis of a substring except from strings between "

javascript regex replace

I have this code which replaced all the occurences of a certain substring inside the string code.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.