diff options
author | Yamagishi Kazutoshi <ykzts@desire.sh> | 2018-06-07 03:50:07 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2018-06-06 20:50:07 +0200 |
commit | 683707839f6e61df95a4958675883c8f80aa6a84 (patch) | |
tree | 8e28834fbe5740f900819555ac126e427b7ee619 | |
parent | c75493755f482d0506884b1f7b7b44e5306a4d8b (diff) |
Fix fetch of remote image with multiple Content-Type headers (#7749)
-rw-r--r-- | app/models/concerns/remotable.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/app/models/concerns/remotable.rb b/app/models/concerns/remotable.rb index 90c6894e0..c17f19a60 100644 --- a/app/models/concerns/remotable.rb +++ b/app/models/concerns/remotable.rb @@ -24,13 +24,14 @@ module Remotable Request.new(:get, url).perform do |response| next if response.code != 200 - content_type = parse_content_type(response.headers['content-type']) + content_type = parse_content_type(response.headers.get('content-type').last) extname = detect_extname_from_content_type(content_type) if extname.nil? - matches = response.headers['content-disposition']&.match(/filename="([^"]*)"/) - filename = matches.nil? ? parsed_url.path.split('/').last : matches[1] - extname = filename.nil? ? '' : File.extname(filename) + disposition = response.headers.get('content-disposition').last + matches = disposition&.match(/filename="([^"]*)"/) + filename = matches.nil? ? parsed_url.path.split('/').last : matches[1] + extname = filename.nil? ? '' : File.extname(filename) end basename = SecureRandom.hex(8) |