goo
goo

Reputation: 2280

Playframework: How do you upload to the tmp folder?

I'm following along with Plays! documentation on uploading files. For some reason when using "/tmp/picture.jpg", my file does not get uploaded to my tmp folder but if I link to it like such /Users/Me/Sites/play-app/tmp/picture.jpg, then it gets uploaded.

So how can I upload files to the tmp folder without giving the that long path? (because I will deploy it soon and the path with not match)

Upvotes: 0

Views: 1010

Answers (1)

Carsten
Carsten

Reputation: 18446

It seems like you are looking for a way to get the absolute path of your Play application. Try this (if you are using Scala):

import play.api.Play
val playroot = Play.application().path().getPath()
val filename = playroot + "/tmp/picture.jpg"

Or, if you are using Java:

import play.*;
String playroot = Play.application().path().getPath();
String filename = playroot + "/tmp/picture.jpg";

Upvotes: 1

Related Questions