Class: CarrierWave::Storage::S3cn::Connection
- Inherits:
-
Object
- Object
- CarrierWave::Storage::S3cn::Connection
- Defined in:
- lib/carrierwave/s3cn/storage.rb
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #download_url(path) ⇒ Object
- #info(key) ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #store(file, key) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/carrierwave/s3cn/storage.rb', line 10 def initialize(={}) @s3cn_region = [:s3cn_region] || 'cn-north-1' @s3cn_endpoint = [:s3cn_endpoint] @s3cn_bucket = [:s3cn_bucket] @s3cn_access_key_id = [:s3cn_access_key_id] @s3cn_secret_access_key = [:s3cn_secret_access_key] @s3cn_protocol = [:s3cn_protocol] @s3cn_bucket_private = [:s3cn_bucket_private] || true init end |
Instance Method Details
#delete(key) ⇒ Object
27 28 29 30 31 32 33 |
# 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) ⇒ Object
39 40 41 42 43 44 45 46 |
# 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) ⇒ Object
35 36 37 |
# File 'lib/carrierwave/s3cn/storage.rb', line 35 def info(key) @s3cn_bucket_obj.objects[key].head end |
#store(file, key) ⇒ Object
21 22 23 24 25 |
# 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 |