class CarrierWave::Storage::AWSFile

Attributes

aws_options[RW]
connection[RW]
file[W]
path[RW]
uploader[RW]

Public Class Methods

new(uploader, connection, path) click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 11
def initialize(uploader, connection, path)
  @uploader    = uploader
  @connection  = connection
  @path        = path
  @aws_options = AWSOptions.new(uploader)
end

Public Instance Methods

attributes() click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 30
def attributes
  file.data.to_h
end
authenticated_url(options = {}) click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 81
def authenticated_url(options = {})
  file.presigned_url(:get, aws_options.expiration_options(options))
end
copy_to(new_path) click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 63
def copy_to(new_path)
  bucket.object(new_path).copy_from(
    "#{bucket.name}/#{file.key}",
    aws_options.copy_options(self)
  )
end
extension() click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 34
def extension
  elements = path.split('.')
  elements.last if elements.size > 1
end
file() click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 18
def file
  @file ||= bucket.object(path)
end
Also aliased as: to_file
filename(options = {}) click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 39
def filename(options = {})
  file_url = url(options)

  CarrierWave::Support::UriFilename.filename(file_url) if file_url
end
move_to(new_path) click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 70
def move_to(new_path)
  file.move_to(
    "#{bucket.name}/#{new_path}",
    aws_options.move_options(self)
  )
end
public_url() click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 85
def public_url
  if uploader.asset_host
    "#{uploader.asset_host}/#{uri_path}"
  else
    file.public_url.to_s
  end
end
read() { |chunk| ... } click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 45
def read
  read_options = aws_options.read_options
  if block_given?
    file.get(read_options) { |chunk| yield chunk }
    nil
  else
    file.get(read_options).body.read
  end
end
signed_url(options = {}) click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 77
def signed_url(options = {})
  signer.call(public_url.dup, options)
end
size() click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 22
def size
  file.size
rescue Aws::S3::Errors::NotFound
  nil
end
store(new_file) click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 55
def store(new_file)
  if new_file.is_a?(self.class)
    new_file.move_to(path)
  else
    file.upload_file(new_file.path, aws_options.write_options(new_file))
  end
end
to_file()
Alias for: file
url(options = {}) click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 93
def url(options = {})
  if signer
    signed_url(options)
  elsif public?
    public_url
  else
    authenticated_url(options)
  end
end

Private Instance Methods

bucket() click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 105
def bucket
  @bucket ||= connection.bucket(uploader.aws_bucket)
end
public?() click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 117
def public?
  uploader.aws_acl.to_s == 'public-read' || uploader.asset_host_public
end
signer() click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 109
def signer
  uploader.aws_signer
end
uri_path() click to toggle source
# File lib/carrierwave/storage/aws_file.rb, line 113
def uri_path
  path.gsub(%r{[^/]+}) { |segment| Seahorse::Util.uri_escape(segment) }
end