Skip to content

Instantly share code, notes, and snippets.

@kuboon
Last active December 16, 2015 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuboon/5494463 to your computer and use it in GitHub Desktop.
Save kuboon/5494463 to your computer and use it in GitHub Desktop.
allow you to send_file with multibyte filename
wget https://gist.github.com/kuboon/5494463/raw/31d80be6dc23eac2bc05d996df1e0293ae001124/send_file_with_utf8.rb -P config/initializers/
module ActionController
module DataStreaming
def send_file_headers_with_utf8!(options)
send_file_headers_without_utf8!(options)
match = /(.+); filename="(.+)"/.match(headers['Content-Disposition'])
encoded = URI.encode_www_form_component(match[2])
headers['Content-Disposition'] = "#{match[1]}; filename*=UTF-8''#{encoded}" unless encoded == match[2]
end
alias_method_chain :send_file_headers!, :utf8
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment