How do you upload a file into the file system in Phoenix?

I want to upload a file to an uploads directory in my application. That’s it…

I’ve searched the web and every example I can find assumes you want to store the file or a reference to it in a database. And the examples seem to indicate that you just add the plug data to a data table’s changeset, save the record and the file is magically uploaded.

Since I don’t want to add anything to any database, how do I just write the temporary file held in the plug data to the file system?

Is it as simple as moving the file that is designated in the plug’s ‘path’ to the upload directory using Elixir file processing?


Yep. I decided to just try it for myself (I should have done that first instead of wasting your time!). Thanks

“Easier than expected” is a common thing in Elixir/Phoenix :wink: