I’m confused about how should I do a model that has some uploaded file, like for exemplo:
User has photos.
I already found out how to upload a file, but the question here is about what to do with the file that was now uploaded, how can I link this new uploaded file(photo in the exemple) with a model(the user in the example).
Thanks.
OBS: Using play for Java here, not Scala.
You have to link your User to his picture. For that, your best option is to use the User id, which should be unique.
Then, if you uploaded your photo under the
pictures/userfolder in your filesystem, then you should save the picture aspictures/user/USER_ID.png(png or jpg or anything else).Then, you can have an action which retrieve the picture according to the user id:
And the Picture class looks like:
I did something similar once (but the pictures were stored in memory), you can take a look here.