Merge pull request #3996 from tchak/download-active-storage-files-through-proxy

Download active_storage blobs through proxy
This commit is contained in:
LeSim 2019-06-26 16:08:30 +02:00 committed by GitHub
commit 4d6719fe7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,6 +25,29 @@ module ActiveStorage
private
def object_for(key, &block)
blob_url = url(key)
if block_given?
request = Typhoeus::Request.new(blob_url)
request.on_headers do |response|
if response.code != 200
raise Fog::OpenStack::Storage::NotFound.new
end
end
request.on_body do |chunk|
yield chunk
end
request.run
else
response = Typhoeus.get(blob_url)
if response.success?
response
else
raise Fog::OpenStack::Storage::NotFound.new
end
end
end
def publicize(url)
search = %r{^https://[^/]+/v1/AUTH_[a-f0-9]{32}}
replace = 'https://static.demarches-simplifiees.fr'