Module: Fog::AWS::S3::Utils

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

Instance Method Summary collapse

Instance Method Details

#parse_data(data) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fog/aws/s3.rb', line 41

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

  if data.is_a?(String)
    [:body] = data
    [:headers]['Content-Length'] = [:body].size.to_s
  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).to_s
  end
  # metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
  
end

#url(params, expires) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/fog/aws/s3.rb', line 62

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