In which directory should I put user generated data?

I don’t think assets is the right folder for it. Should I create a new directory for it? What is the best practice in Phoenix projects? Think of users generated pdf files or uploaded images etc.

1 Like

You are right to think assets is not the place… it should be either a place served by plug static, or anywhere, served by a controller.

I prefer the second, as it allows access checking.

2 Likes

The best practice is some sort of Cloud Storage. S3, Cloud Storage, Digital Ocean’s cloud spaces, etc. If you store it on the server there is no good way to run multiple nodes, and cloud storage generally allows you to provide the end user with signed links that let them download the objects directly without routing the data through your server.

10 Likes

I use cloud storage for Metamorphic like @benwilson512 suggests.

I also use the ex_aws APIs for this, but there are other options too.

For us, we have to store lots of images (avatars and memories) for people, so something like S3 is great and you can always adapt to any cloud provider that has a S3 API support, like Storj.

We are storing already encrypted data files in the cloud (so the cloud provider just gets an encrypted blob and then adds their own encryption on top of that) and then handling the temporary decryption and storage with ETS during someone’s session.

I reached out to my hosting provider and they also agreed that cloud storage is the way to go especially if you plan to support your system at scale (images can add up!).

Then, if your service scales enough you can always hire a team and start to build out your own cloud.

But, yea the agreed best practice is to go to the cloud if you’re planning to grow and then revisit from there.

Uploads resources
Live View: You can go direct-to-server or direct-to-cloud with Live View. You can also combine with Waffle for image transformations or roll them yourself.

Controller: I’m less familiar here but you can use the same ex_aws APIs and Waffle or other for transformations.

2 Likes