odbhut.shei.chhele
odbhut.shei.chhele

Reputation: 6224

scala/play - Make a File object from an uploaded file

I am using scala playframework. I am uploading a file. On the server side I am receiving the file successfully. I want to create a File object from it. How to do it?

Here is the code that I have written so far.

  request.body.file("dataFile").map(
    currentFile => {
      // How to make a FILE object from currentFile
      //Something like
      //val file: File = new File(currentFile)
    }
  )

Is it possible? If so then how? Thanks in advance.

Upvotes: 1

Views: 150

Answers (1)

Peanut
Peanut

Reputation: 3963

According to the documentation it should work this way:

  request.body.file("dataFile").map(
    currentFile => {
      // How to make a FILE object from currentFile
      import java.io.File
      val filename = currentFile.filename
      val contentType = currentFile.contentType
      val myFile = new File(s"/tmp/somepath/$filename")
      currentFile.ref.moveTo(myFile)
      //now "myFile" is an object of type "File".
    }
  )

Upvotes: 1

Related Questions