Hello guys,
I have weird problem with :accepts
inside my plug. My controller action is plugged to the pipeline below.
pipeline :browser do
plug(:accepts, ["html", "image"])
end
Inside my config file i have mime described as: config :mime, :types, %{"image/*" => ["image"]}
And inside my controller I have this code:
file_path = Web.Env.path("priv/static/img/pixel.png")
send_download(conn, {:file, file_path})
And when I’m testing this on my local environment or even prod environment everything works fine. But there are some cases, which I don’t know why happens. When function with send_download
returns:
Phoenix.NotAcceptableError
no supported media type in accept header.
Expected one of ["html", "image"] but got the following formats:
* "image/webp" with extensions: ["webp"]
"image/png" with extensions: ["png"]
"image/jpeg" with extensions: ["jpg", "jpeg", "jpe", "jfif"]
"image/gif" with extensions: ["gif"]
To accept custom formats, register them under the :mime library
in your config/config.exs file:
config :mime, :types, %{
"application/xml" => ["xml"]
}
And then run `mix deps.clean --build mime` to force it to be recompiled.
Can someone explain me what am I doing wrong? Why does it only sometimes doesn’t work?