Reputation: 4091
If I do a file upload to the file system (to the public assets directory) in production mode, the file is not served afterwards. I need to run the clean command. I get a file not found error. How can I avoid this?
Upvotes: 3
Views: 1243
Reputation: 55798
Although sending files as an action's Result is possible (what you proved) I'd suggest to store public uploads outside of the application and serving it with common HTTP server.
Reasons are simple:
Upvotes: 3
Reputation: 4091
I added a custom Assets controller, now it seems to work properly:
package customcontrollers
import controllers.Assets
import play.api.mvc.Action
import play.api.mvc.AnyContent
import play.api.mvc.Results.Ok
import play.api.Play.current
import play.api._
object UploadedImageAssets {
def at(file: String): Action[AnyContent] = Action {
Ok.sendFile(Play.getFile("public/uploaded-images/"+file))
}
}
Upvotes: 0
Reputation: 7877
I don't like this answer, but there is no way to achieve this easily.
Because, "it's not a very good way to do things, it is unreliable, it doesn't scale, and there are security concerns". (I don't agree with this, but it's a fact).
The best solution is to store your file in a database, or to upload it to another service like S3.
Upvotes: 3