0%

ruby真好用啊

ruby没有python那么难用,虽然python功能也很强 。

用ruby上传下载文件到amazons3 ,几句代码搞定。

1 gem install aws-sdk

2

 

 

AWS.config(
:access_key_id => 'xxxxxxxxxx',
:secret_access_key => 'xxxxxxxxxxxxxxx')

s3=AWS::S3.new
s3.buckets.each do|bucket|
puts bucket.name
end

#upload
b =s3.buckets['test']
obj=b.objects['ttt/11.jpg']
puts obj

obj.write(Pathname.new('h:/2.jpg'),:acl=>'public_read')
#downloading file
obj=b.objects['100.jpg']
jpg=obj.read
File.open('h:/1001.jpg', 'wb') do |file|
obj.read do |chunk|
file.write(chunk)
end
end