2013-03-14 115 views

回答

7

簡單:

require 'open-uri' 
require 's3' 

amazon = S3::Service.new(access_key_id: 'KEY', secret_access_key: 'KEY') 
bucket = amazon.buckets.find('image_storage') 
url = 'http://www.example.com/url' 
download = open(url) 

file = bucket.objects.build('image.png') 
file.content = (File.read download) 

if file.save 
    # Make a new ActiveRecord::Base class for this 
    LogFile.create(size: download.size, type: download.type, name: url) 
end 

https://github.com/qoobaa/s3

+0

你在哪裏寫的嗎? – 2ueenO 2013-12-10 15:46:03

+0

在一個純文本文件中,然後用'$ ruby​​ file.rb'(?) – nicooga 2013-12-10 17:52:15

+0

運行它,但是我的解決方案非常有趣,我想將它插入我的網站以存儲來自鳥舍的圖片。我創建了另一個問題:[在S3中從一個臨時URL保存圖片](http://stackoverflow.com/questions/20500057/save-a-picture-in-s3-from-a-temporary-url) – 2ueenO 2013-12-10 18:09:02

相關問題