Browse Source

Fix fetch of remote image with multiple Content-Type headers (#7749)

pull/4/head
Yamagishi Kazutoshi 5 years ago
committed by Eugen Rochko
parent
commit
683707839f
1 changed files with 5 additions and 4 deletions
  1. +5
    -4
      app/models/concerns/remotable.rb

+ 5
- 4
app/models/concerns/remotable.rb View File

@ -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)

Loading…
Cancel
Save