Class: CarrierWave::Storage::RightS3::File

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/storage/right_s3.rb

Instance Method Summary collapse

Constructor Details

#initialize(uploader, base, path) ⇒ File

Returns a new instance of File.



50
51
52
53
54
# File 'lib/carrierwave/storage/right_s3.rb', line 50

def initialize(uploader, base, path)
  @uploader = uploader
  @path = path
  @base = base
end

Instance Method Details

#content_typeObject



102
103
104
# File 'lib/carrierwave/storage/right_s3.rb', line 102

def content_type
  headers["content-type"]
end

#deleteObject

Remove the file from Amazon S3



83
84
85
# File 'lib/carrierwave/storage/right_s3.rb', line 83

def delete
  connection.delete(bucket, @path)
end

#pathObject

Returns the current path of the file on S3

Returns

String

A path



63
64
65
# File 'lib/carrierwave/storage/right_s3.rb', line 63

def path
  @path
end

#readObject

Reads the contents of the file from S3

Returns

String

contents of the file



74
75
76
77
78
# File 'lib/carrierwave/storage/right_s3.rb', line 74

def read
  result = connection.get(bucket, @path)
  @headers = result[:headers]
  result[:object]
end

#store(file) ⇒ Object

def content_disposition

s3_object.content_disposition

end



110
111
112
113
114
115
# File 'lib/carrierwave/storage/right_s3.rb', line 110

def store(file)
  connection.put(bucket, @path, file.read,
    'x-amz-acl' => @uploader.s3_access_policy,
    'content-type' => file.content_type
  )
end

#urlObject

Returns the url on Amazon’s S3 service

Returns

String

file’s url



94
95
96
97
98
99
100
# File 'lib/carrierwave/storage/right_s3.rb', line 94

def url
  if @uploader.s3_cnamed
    ["http://", @uploader.s3_bucket, "/", @path].compact.join
  else
    ["http://s3.amazonaws.com/", @uploader.s3_bucket, "/", @path].compact.join
  end
end