Simon Simon - 1 month ago 5x
Scala Question

Is it possible to access a file outside a Play! application folder?

I would like to let two Play applications( deployed on the same server) to access a same folder, but I don't find the way to do it.

Is it possible to access a file by its absolute path, so I could put this folder at the directory level of my server and access it by the two applications?


Yes it is possible to access any folder given correct permissions to the play app process. You could access any file in the filesystem using Java file.

Ensure read write permissions accordingly if not Play throws FileNotFoundException


class ApplicationController @Inject() () extends Controller {
 def file = Action {
  Ok.sendFile(new File(s"${sys.props("user.home")}/some_file.txt"))

In the above example some_file.txt is send over http connection. Note that if permission are not correct then it will throw FileNotFoundException