Reputation: 6224
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
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