dmitriid
TIL: proper content-disposition to download files with UTF-8 names
This is not a question, but a post for anyone who may need it in the future. Sometimes some browsers may mangle the filename if it’s non-ASCII characters even if everything is in bloody UTF-8.
Picture worth a thousand words. Safari dowloands. Below: before. Above: after
The fix in its entirety:
file = "/path/to/your/file"
file_name = <get the name of the file if you want it to look nice>
file_extension = <file extension. For example, Path.extname(file)>
content_type = <MIME content type, e.g. text/plain etc.>
file_name_escaped = URI.encode(file_name)
conn
|> put_resp_content_type(content_type, "utf-8")
|> put_resp_header(
"content-disposition",
"attachment;filename=\"#{file_name}.#{file_extension}\";filename*=utf-8''#{file_name_escaped}.#{file_extension}"
)
|> send_file(200, user_book.file)
The actual fix is adding ;filename*=utf-8''<url-encoded file name>
Hope this helps someone
Popular in Guides/Tuts
So I’m really loving elixir. BY FAR the most excruciating piece of learning a functional language for me is having to “transform” all my ...
New
Me and my boys started a new website specifically designed for other ASP.NET programmers that struggle, as we do, with their transformati...
New
Did you know that IO.inspect/2 returns the the first argument and accepts a label option as a second argument. This makes it a perfect to...
New
In a quest to optimize the amount of data sent between the server and client I recently decided to try to use MessagePack instead of JSON...
New
Just leaving some breadcrumbs for future me and future others like me.
Connect with TCP (not secured) - most servers will reject but use...
New
I wrote this blog post based on our experiences setting up continuous delivery for our first production umbrella Phoenix app. Coming from...
New
Hi,
TLDR: form attribute set on the input fields and button submit.
I just wanted to share a solution I discovered when making live inl...
New
This is a thread to note down things/best practices encountered in LiveBeats App as I explore the source code.
Found this usage of r...
New
Hi guys,
I’ve been on a personal journey to learn Elixir for the past two years. During this journey I’ve been using the spaced repetiti...
New
Hey all! I put together a starter-pack / instructions to set up Phoenix with the new parcel-bundler instead of brunch (or webpack).
It’s...
New
Other popular topics
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
can someone please explain to me how Enum.reduce works with maps
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New








