Class: CarrierWave::Storage::S3::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::S3::File
- Defined in:
- lib/carrierwave/storage/s3.rb
Instance Method Summary (collapse)
- - (Object) authenticated_url
- - (Object) content_type
- - (Object) content_type=(type)
-
- (Object) delete
Remove the file from Amazon S3.
-
- (Object) headers
Headers returned from file retrieval.
-
- (File) initialize(uploader, base, path)
constructor
A new instance of File.
-
- (Object) path
Returns the current path of the file on S3.
- - (Object) public_url
-
- (Object) read
Reads the contents of the file from S3.
- - (Object) size
- - (Object) store(file)
-
- (Object) url
Returns the url on Amazon's S3 service.
Constructor Details
- (File) initialize(uploader, base, path)
A new instance of File
73 74 75 76 77 |
# File 'lib/carrierwave/storage/s3.rb', line 73 def initialize(uploader, base, path) @uploader = uploader @path = path @base = base end |
Instance Method Details
- (Object) authenticated_url
133 134 135 |
# File 'lib/carrierwave/storage/s3.rb', line 133 def authenticated_url connection.get_object_url(bucket, path, Time.now + 60 * 10) end |
- (Object) content_type
147 148 149 |
# File 'lib/carrierwave/storage/s3.rb', line 147 def content_type headers["Content-Type"] end |
- (Object) content_type=(type)
151 152 153 |
# File 'lib/carrierwave/storage/s3.rb', line 151 def content_type=(type) headers["Content-Type"] = type end |
- (Object) delete
Remove the file from Amazon S3
106 107 108 |
# File 'lib/carrierwave/storage/s3.rb', line 106 def delete connection.delete_object(bucket, @path) end |
- (Object) headers
Headers returned from file retrieval
160 161 162 163 164 165 166 |
# File 'lib/carrierwave/storage/s3.rb', line 160 def headers @headers ||= begin connection.head_object(bucket, @path).headers rescue Excon::Errors::NotFound # Don't die, just return no headers {} end end |
- (Object) path
Returns the current path of the file on S3
Returns
- String
-
A path
86 87 88 |
# File 'lib/carrierwave/storage/s3.rb', line 86 def path @path end |
- (Object) public_url
125 126 127 128 129 130 131 |
# File 'lib/carrierwave/storage/s3.rb', line 125 def public_url if cnamed? ["http://#{bucket}", path].compact.join('/') else ["http://#{bucket}.s3.amazonaws.com", path].compact.join('/') end end |
- (Object) read
Reads the contents of the file from S3
Returns
- String
-
contents of the file
97 98 99 100 101 |
# File 'lib/carrierwave/storage/s3.rb', line 97 def read result = connection.get_object(bucket, @path) @headers = result.headers result.body end |
- (Object) size
155 156 157 |
# File 'lib/carrierwave/storage/s3.rb', line 155 def size headers['Content-Length'].to_i end |
- (Object) store(file)
137 138 139 140 141 142 143 144 145 |
# File 'lib/carrierwave/storage/s3.rb', line 137 def store(file) content_type ||= file.content_type # this might cause problems if content type changes between read and upload (unlikely) connection.put_object(bucket, path, file.read, { 'x-amz-acl' => access_policy.to_s.gsub('_', '-'), 'Content-Type' => content_type }.merge(@uploader.s3_headers) ) end |
- (Object) url
Returns the url on Amazon's S3 service
Returns
- String
-
file's url
117 118 119 120 121 122 123 |
# File 'lib/carrierwave/storage/s3.rb', line 117 def url if access_policy == :authenticated_read authenticated_url else public_url end end |