Module: Fog::AWS::Storage::Utils

Included in:
Mock, Real
Defined in:
lib/fog/storage/aws.rb

Instance Method Summary collapse

Instance Method Details

#cdnObject



67
68
69
70
71
72
# File 'lib/fog/storage/aws.rb', line 67

def cdn
  @cdn ||= Fog::AWS::CDN.new(
    :aws_access_key_id => @aws_access_key_id,
    :aws_secret_access_key => @aws_secret_access_key
  )
end

#parse_data(data) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fog/storage/aws.rb', line 74

def parse_data(data)
   = {
    :body => nil,
    :headers => {}
  }

  if data.is_a?(String)
    [:body] = data
    [:headers]['Content-Length'] = [:body].size
  else
    filename = ::File.basename(data.path)
    unless (mime_types = MIME::Types.of(filename)).empty?
      [:headers]['Content-Type'] = mime_types.first.content_type
    end
    [:body] = data
    [:headers]['Content-Length'] = ::File.size(data.path)
  end
  # metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
  
end

#url(params, expires) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/fog/storage/aws.rb', line 95

def url(params, expires)
  params[:headers]['Date'] = expires.to_i
  params[:path] = CGI.escape(params[:path]).gsub('%2F', '/')
  query = [params[:query]].compact
  query << "AWSAccessKeyId=#{@aws_access_key_id}"
  query << "Signature=#{CGI.escape(signature(params))}"
  query << "Expires=#{params[:headers]['Date']}"
  bucket = params[:host].split('.').first
  "https://#{@host}/#{params[:path]}?#{query.join('&')}"
end