FCC SpeedRun #3: File Metadata
After finishing the Timestamp Microservice, I started with the FileMetadata Micro service.
Now the FCC FileMetadata Micro service is quite straightforward. You upload a file, the service responds with the size of the file.
Elixir has built in support for getting the stats of a file. (See official docs.) So there was no issue in figuring out the file size, the interesting part was to make a multipart form which could upload a file.
Now I could make an HTML form like this —
<form action="/file-size" enctype="multipart/form-data" method="post">
</form>
But before writing that code I checked out the official Phoenix docs and found this.
<%= form_for @changeset, @action, [multipart: true], fn f -> %>
This is just Phoenix template which makes creating forms and other HTML elements a breeze.
So I used the above code and finished my app.
However there was a problem, I was unable to upload files larger than 8MB, because that was Phoenix’s file size limit. To fix that I just had to change the default value by increasing the limit in the endpoint.ex file. I increased the limit like so —
length: 100_000_000
And Voila! I was able to upload larger files.
You can view the deployed app here.