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
Wrote this guide on how to integrate DropzoneJS with Phoenix Liveview. Hope it helps someone out!
https://sergiotapia.com/dropzonejs-dir...
New
I was preparing to deploy a production application to AWS Fargate, and to practice I wanted to play with DNS polling and node discovery o...
New
Hi everyone!
I’m the founder of Render, a new cloud provider with native support for Elixir. When we launched Elixir support the most po...
New
Hey friends, wanted to share a tiny shell script I’ve been using to start Livebook with easy access to either a running production server...
New
So here is the code I came up with to generically generate an array param that will be stored on a jsonb property in ecto.
It only handl...
New
To integrate dropdown menus in a Phoenix Liveview app, you can use a combination of js, Hooks, CSS and your .leex and .ex code. You can...
New
Hi everyone,
I’m the founder of Render and we just released a guide to deploying Phoenix apps with Mix releases.
Most of it is generali...
New
Hello,
While answering a StackOverflow question on how to debug an elixir node running remotely, I thought it may be helpful to write a...
New
Hey, today I give amnesia library a try and found a few problems. I would like describe how to setup it properly and solve problems which...
New
I have published an elixir project with using Travis CI.
I would like to share some tips & thoughts that I was getting through this ...
New
Other popular topics
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New








