Class: CarrierWave::Storage::S3::File

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

Instance Method Summary collapse

Constructor Details

#initialize(uploader, path) ⇒ File

Returns a new instance of File.



56
57
58
59
# File 'lib/carrierwave/storage/s3.rb', line 56

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

Instance Method Details

#aboutObject



105
106
107
# File 'lib/carrierwave/storage/s3.rb', line 105

def about
  s3_object.about
end

#content_dispositionObject



121
122
123
# File 'lib/carrierwave/storage/s3.rb', line 121

def content_disposition
  s3_object.content_disposition
end

#content_disposition=(new_disposition) ⇒ Object



125
126
127
# File 'lib/carrierwave/storage/s3.rb', line 125

def content_disposition=(new_disposition)
  s3_object.content_disposition = new_disposition
end

#content_typeObject



113
114
115
# File 'lib/carrierwave/storage/s3.rb', line 113

def content_type
  s3_object.content_type
end

#content_type=(new_content_type) ⇒ Object



117
118
119
# File 'lib/carrierwave/storage/s3.rb', line 117

def content_type=(new_content_type)
  s3_object.content_type = new_content_type
end

#deleteObject

Remove the file from Amazon S3



86
87
88
# File 'lib/carrierwave/storage/s3.rb', line 86

def delete
  AWS::S3::S3Object.delete @path, @uploader.s3_bucket
end

#metadataObject



109
110
111
# File 'lib/carrierwave/storage/s3.rb', line 109

def 
  s3_object.
end

#pathObject

Returns the current path of the file on S3

Returns

String

A path



68
69
70
# File 'lib/carrierwave/storage/s3.rb', line 68

def path
  @path
end

#readObject

Reads the contents of the file from S3

Returns

String

contents of the file



79
80
81
# File 'lib/carrierwave/storage/s3.rb', line 79

def read
  AWS::S3::S3Object.value @path, @uploader.s3_bucket
end

#s3_objectObject



133
134
135
# File 'lib/carrierwave/storage/s3.rb', line 133

def s3_object
  @s3_object ||= AWS::S3::S3Object.find(@path, bucket)
end

#storeObject



129
130
131
# File 'lib/carrierwave/storage/s3.rb', line 129

def store
  s3_object.store
end

#urlObject

Returns the url on Amazon’s S3 service

Returns

String

file’s url



97
98
99
100
101
102
103
# File 'lib/carrierwave/storage/s3.rb', line 97

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