Last active
December 16, 2015 20:39
-
-
Save kuboon/5494463 to your computer and use it in GitHub Desktop.
allow you to send_file with multibyte filename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget https://gist.github.com/kuboon/5494463/raw/31d80be6dc23eac2bc05d996df1e0293ae001124/send_file_with_utf8.rb -P config/initializers/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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