class CarrierWave::Storage::S3cn::Connection

Public Class Methods

new(options={}) click to toggle source
# File lib/carrierwave/s3cn/storage.rb, line 10
def initialize(options={})
  @s3cn_region = options[:s3cn_region] || 'cn-north-1'
  @s3cn_endpoint = options[:s3cn_endpoint]
  @s3cn_bucket = options[:s3cn_bucket]
  @s3cn_access_key_id = options[:s3cn_access_key_id]
  @s3cn_secret_access_key = options[:s3cn_secret_access_key]
  @s3cn_protocol = options[:s3cn_protocol]
  @s3cn_bucket_private = options[:s3cn_bucket_private] || true
  init
end

Public Instance Methods

delete(key) click to toggle source
# File lib/carrierwave/s3cn/storage.rb, line 27
def delete(key)
  begin
    @s3cn_bucket_obj.objects[key].delete
  rescue Exception
    nil
  end
end
download_url(path) click to toggle source
# File lib/carrierwave/s3cn/storage.rb, line 39
def download_url(path)
  if @s3cn_bucket_private
    temp_url = @s3cn_bucket_obj.objects[path].url_for(:get, :signature_version => :v4).to_s
  else
    temp_url = @s3cn_bucket_obj.objects[path].public_url.to_s
  end
  temp_url
end
info(key) click to toggle source
# File lib/carrierwave/s3cn/storage.rb, line 35
def info(key)
  @s3cn_bucket_obj.objects[key].head
end
store(file, key) click to toggle source
# File lib/carrierwave/s3cn/storage.rb, line 21
def store(file, key)
  stored_file = file.to_file
  @s3cn_bucket_obj.objects.create(key, stored_file)
  stored_file.close if stored_file && !stored_file.closed?
end

Private Instance Methods

init() click to toggle source
# File lib/carrierwave/s3cn/storage.rb, line 50
def init
  init_s3cn_connection 
end
init_s3cn_connection() click to toggle source
# File lib/carrierwave/s3cn/storage.rb, line 54
def init_s3cn_connection
  return if !@s3cn.nil?
  temp_config = {:access_key_id => @s3cn_access_key_id, :secret_access_key => @s3cn_secret_access_key, :region => @s3cn_region}
  @s3cn = AWS::S3.new(temp_config)
  @s3cn_bucket_obj = @s3cn.buckets[@s3cn_bucket]
end