I’m building a file converter website which does not require an account. It stores all conversions in the database and assigns owned conversions to a session as a list of IDs.
I don’t use S3 yet, so all converted files are stored in a priv/static/uploads.
defmodule MyAppWeb do
def static_paths, do: ~w(uploads
These files are mostly stored temporarily and deleted after 24 hours. But there would be the case when we store them longer if someone makes an account.
Is it acceptable to keep these files publicly exposed? Is it better to somehow authenticate access to these files? If so, is there an easy way to do so with Plug/Phoenix?
You can just use authentication plug for the static files?
The way I did it back in the day is that I would have a dedicated controller that would serve the files based on the authenticated user, as most probably you won’t want authenticated users to see each-other’s files.
Thank you! A dedicated controller for serving files seems to be what I want. I can also make it domain-specific so that it fetches the database record and checks the ownership to then decide whether to serve the file.
I now think my file-serving controller could benefit from utilizing Nginx’s X-Accel-Redirect header to send over large files.
You could give each file an unguessable “token” and allow download via that token. Depending on your use case this could be handy for allowing a user to send the download link to someone else (or another computer).
If a logged-in user wants a truly “private” (authenticated) upload then you could make the token optional in the schema (or better, a “visibility” field) and authenticate accordingly.