Elixir Phoenix
Learn how to configure an Elixir Phoenix App for use with Filebase.
What is Elixir Phoenix?
Elixir Phoenix is a web framework built using the Elixir programming language. It is designed to help developers quickly build scalable and fault-tolerant web applications that can handle large amounts of traffic. Phoenix provides many features that are common to modern web frameworks, including a request/response cycle, a routing system, controllers, views, and templates. It is a popular choice for building real-time applications, such as chat apps, games, and social media platforms, as well as traditional web applications.
Read below to learn how to use Elixir Phoenix with Filebase.
1. Create a new Elixir project with the command:
mix phx.new file_upload_app
cd file_upload_app
2. Next, create a new database with the command:
mix ecto.create
3. Then, add the Ex.Aws.S3 package to your Elixir list of dependencies in your project’s mix.esc
file:
mix.esc
file:4. Install these dependencies with the command:
mix deps.get
5. Configure the Ex.Aws.S3 package to use your FIlebase instance with the following configuration in your project’s config/config.exs
file:
config/config.exs
file:Replace ‘bucket-name
’ with your Filebase bucket name.
6. Create a .env
file with the following environment variables:
.env
file with the following environment variables:7. Then, source this environmental variable file with the command:
source .env
8. Next, in the lib/file_upload_app_web/router.ex
file, add the following code:
lib/file_upload_app_web/router.ex
file, add the following code:9. Create a new migration with the command:
mix ecto.gen.migration add_uploads
10. This command will create a new file located at priv/repo/migrations/add_uploads.exs
. Open this file and insert the following code:
priv/repo/migrations/add_uploads.exs
. Open this file and insert the following code:11. Then apply the changes to the Elixir project with the command:
mix ecto.migrate
12. Within the file_upload_app_web
folder, create a new folder called models
, with a new file inside called upload.ex
. Insert the following code:
file_upload_app_web
folder, create a new folder called models
, with a new file inside called upload.ex
. Insert the following code:13. Next, within the templates
folder, create a new folder called upload
, then within that folder create a new file called new.html.eex
. Inside this new file, insert the following:
templates
folder, create a new folder called upload
, then within that folder create a new file called new.html.eex
. Inside this new file, insert the following:14. Lastly, create a new upload_controller.ex
file in the controllers folder. Add the following code to the file:
upload_controller.ex
file in the controllers folder. Add the following code to the file:15. Now it’s time to start the server. Use the command:
mix phoenix.server
16. The server will start on localhost:4000
. Open this in a web browser, then go to localhost:4000/uploads/new
to upload a file.
localhost:4000
. Open this in a web browser, then go to localhost:4000/uploads/new
to upload a file.Last updated