Working with uploads in Phoenix

Phoenix doesn't have anything built into its directory structure to store uploaded files, so that's something we'll have to write ourselves. We'll start off by creating a new directory in the root of our application called uploads in the root directory of our Phoenix application. We'll also want to make sure that the directory is included if we're using something like Git for source control:

$ mkdir uploads$ touch uploads/.gitkeep

We'll also have to modify our endpoint to allow serving files from this new directory. To do this, you tell Phoenix that, as part of the plugs responsible for keeping the server alive and moving, you'll also include a line for Plug.Static telling it that there is a new directory for ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.