shahryarjb
Hello, I need to create a custom massage or page for Sending large request, for example if my user sends a file larger than 2 mg, my code shows them a page or redirect or something except default massage,
I have edited this line in endpoint.ex
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
body_reader: {WeddingCardWeb.DashboardController, :body_of_upload, []},
json_decoder: Phoenix.json_library()
and my functions in my controller is:
def body_of_upload(conn, _opts) do
conn
|> put_flash(:error, "متاسفانه فایل ارسالدر مواردی مثل حجم و فرمت مجاز دارای مشکل می باشد.")
|> redirect(to: "/dashboard")
end
but it doesn’t work.
By the way, can I create a preventer to limit my user sending upload file in my function:
def upload(conn, params) do
with {:ok, user_id} <- check_session(conn, :user_login_id), {:ok, invoice_id_valid} <- Ecto.UUID.cast(params["invoice_id"]),
{:ok, user_infos} <- WeddingCardWeb.LoginController.user_find_pattern(user_id), true <- user_infos.status,
{:ok, invoice_info} <- invoice_pattern_by_id(invoice_id_valid),
{:ok, :belong_user} <- invoice_belong_user_pattern(user_id, invoice_info.wedding_user_id),
{:ok, upload} <- upload_check(params["upload"]), {:ok, [file_name]} <- file_name_reader(upload),
true <- validate_file(file_name),
nil <- WeddingCard.DB.UploadQuery.get_upload_by_invoice_id(invoice_info.id) do
[%{file_size: size, file_name: name_of_file}] = config_file(upload)
# Store in db
WeddingCard.DB.UploadQuery.insert_upload(%{
"wedding_user_id" => user_infos.id,
"wedding_invoice_id" => invoice_info.id,
"size" => "#{size}",
"address" => "#{name_of_file}"
})
conn
|> put_flash(:info, "فایل شما با موفقیت آپلود گردید")
|> redirect(to: "/dashboard")
else
_ ->
conn
|> put_flash(:error, "متاسفانه فایل مذکور ارسال نگردید یا در فرمت و حجم مناسب نبوده است. توجه فرمایید شما فقط مجاز به ارسال فایل برای یک بار هستید.")
|> redirect(to: "/dashboard")
end
end
all the functions I called top in my function, they work after uploaded file!!!
for example:
def validate_file(filename) do
~w(.jpg .jpeg .xlsx .png .JPG .pdf .docx) |> Enum.member?(Path.extname(filename))
end
it works after uploading, but the file concerned is bigger than my limitation, and my project shows me a default massage like this that I don’t want it.
Request Entity Too Large
Thanks
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
josevalim
If you are using Phoenix, you can customize the error pages in the MyApp.ErrorView module. Request Entity Too Large has the status code of 413.
shahryarjb
Thank you, but how can I do this in my function that receives upload file ?
shahryarjb
Hello, is there any option which helps me to handle error in my controller function ?