Class: Syncbox::S3Bucket
- Inherits:
-
Object
- Object
- Syncbox::S3Bucket
- Defined in:
- lib/syncbox/store/s3_bucket.rb
Instance Method Summary collapse
-
#delete(file_path) ⇒ Object
delete file from bucket.
-
#initialize(options) ⇒ S3Bucket
constructor
Initializes a s3 bucket object.
-
#upload(file_path) ⇒ Object
Uploads file to bucket.
Constructor Details
#initialize(options) ⇒ S3Bucket
Initializes a s3 bucket object
options must include:
-
access_key_id
-
secret_access_key
-
bucket_name
Note: modify the local files, triggers upload.
Upload same name file, S3 will automatically replaced the original file.
Cancel the upload in the middle of uploading will not replace the originmal file.
19 20 21 22 23 24 25 |
# File 'lib/syncbox/store/s3_bucket.rb', line 19 def initialize() arguement_check() s3 = AWS::S3.new(:access_key_id => ["access_key_id"], :secret_access_key => ["secret_access_key"]) bucket_name = ["bucket_name"] @bucket = s3.buckets[bucket_name] remote_accessible_check end |
Instance Method Details
#delete(file_path) ⇒ Object
delete file from bucket.
46 47 48 49 50 |
# File 'lib/syncbox/store/s3_bucket.rb', line 46 def delete(file_path) file_name = File.basename(file_path) object = @bucket.objects[file_name] object.delete end |
#upload(file_path) ⇒ Object
Uploads file to bucket.
33 34 35 36 37 38 |
# File 'lib/syncbox/store/s3_bucket.rb', line 33 def upload(file_path) file_name = File.basename(file_path) object = @bucket.objects[file_name] object.write(:file => file_path) object.public_url end |