Method: AssetS3::S3.upload

Defined in:
lib/asset_s3.rb

.upload(options = {}) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/asset_s3.rb', line 85

def self.upload(options={})
  connect_to_s3
  assets.each do |asset|
    puts "asset_id: Uploading #{asset} as #{fingerprint(asset)}" if options[:debug]
    mime_type = MIME::Types.of(asset).first.to_s

    headers = {
      :content_type => mime_type,
      :access => s3_permissions,
    }.merge(cache_headers)

    if gzip_types.include?(mime_type)
      data = `gzip -c #{asset}`
      headers.merge!(gzip_headers)
    else
      data = File.read(asset)
    end

    puts "asset_id: headers: #{headers.inspect}" if options[:debug]

    AWS::S3::S3Object.store(
      fingerprint(asset),
      data,
      s3_bucket,
      headers
    ) unless options[:dry_run]
  end
end