class Filestorage::AmazonS3
Public Class Methods
new(bucket, access_key_id, secret_access_key)
click to toggle source
# File lib/filestorage-s3/amazon_s3.rb, line 11 def initialize(bucket, access_key_id, secret_access_key) @s3 = AWS::S3.new(:access_key_id => access_key_id, :secret_access_key => secret_access_key) @bucket = @s3.buckets[bucket] end
Public Instance Methods
delete(path)
click to toggle source
# File lib/filestorage-s3/amazon_s3.rb, line 37 def delete(path) obj = @bucket.objects[path] raise NotExist.new("Not exist #{path}") unless obj.exists? obj.delete path end
exist?(path)
click to toggle source
# File lib/filestorage-s3/amazon_s3.rb, line 44 def exist?(path) obj = @bucket.objects[path] obj.exists? end
files()
click to toggle source
# File lib/filestorage-s3/amazon_s3.rb, line 49 def files files = [] @bucket.objects.each do |obj| files << obj.key end files end
get(path)
click to toggle source
# File lib/filestorage-s3/amazon_s3.rb, line 31 def get(path) obj = @bucket.objects[path] raise NotExist.new("Not exist #{path}") unless obj.exists? obj end
store(path, file)
click to toggle source
# File lib/filestorage-s3/amazon_s3.rb, line 17 def store(path, file) obj = @bucket.objects[path] raise AlreadyExist.new("Already exist #{path}") if obj.exists? content = if file.instance_of?(Pathname) File.open(file, "rb"){|f| f.read} elsif file.instance_of?(File) file.read else file end obj.write(content, :acl => :public_read) path end