1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Return nil on public_url if the file isn't present on the cloud storage

This commit is contained in:
Michael Harrison 2012-10-17 13:40:41 +10:00
parent c9dd0eb5c2
commit 7c2fb4c6c0

View file

@ -57,18 +57,21 @@ module Fog
# By default, expire in 5 years
def public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60))
self.objectid = directory.files.head(key).attributes['x-emc-meta'].scan(/objectid=(\w+),/).flatten[0] if self.objectid.blank?
requires :objectid
uri = URI::HTTP.build(:scheme => connection.ssl? ? "http" : "https" , :host => connection.host, :port => connection.port.to_i, :path => "/rest/objects/#{self.objectid}" )
file = directory.files.head(key)
if file.present?
self.objectid = file.attributes['x-emc-meta'].scan(/objectid=(\w+),/).flatten[0] if self.objectid.blank?
requires :objectid
uri = URI::HTTP.build(:scheme => connection.ssl? ? "http" : "https" , :host => connection.host, :port => connection.port.to_i, :path => "/rest/objects/#{self.objectid}" )
sb = "GET\n"
sb += uri.path.downcase + "\n"
sb += connection.uid + "\n"
sb += String(expires.to_i())
sb = "GET\n"
sb += uri.path.downcase + "\n"
sb += connection.uid + "\n"
sb += String(expires.to_i())
signature = connection.sign( sb )
uri.query = "uid=#{CGI::escape(connection.uid)}&expires=#{expires.to_i()}&signature=#{CGI::escape(signature)}"
uri.to_s
signature = connection.sign( sb )
uri.query = "uid=#{CGI::escape(connection.uid)}&expires=#{expires.to_i()}&signature=#{CGI::escape(signature)}"
uri.to_s
end
end
def save(options = {})