Class: Syncbox::S3Bucket

Inherits:
Object
  • Object
show all
Defined in:
lib/syncbox/store/s3_bucket.rb

Instance Method Summary collapse

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.

Parameters:

  • options (Hash)


19
20
21
22
23
24
25
# File 'lib/syncbox/store/s3_bucket.rb', line 19

def initialize(options)
  arguement_check(options)
  s3 = AWS::S3.new(:access_key_id => options["access_key_id"], :secret_access_key => options["secret_access_key"])
  bucket_name = options["bucket_name"]
  @bucket = s3.buckets[bucket_name]
  remote_accessible_check
end

Instance Method Details

#delete(file_path) ⇒ Object

delete file from bucket.

Parameters:

  • file_path (String)

Returns:

  • nil



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.

Parameters:

  • file_path (String)

Returns:

  • a public (not authenticated) URL for the object



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