[英]Rails: Can't save file from URL and save it to Amazon S3 (S3::Error::ResponseError)
[英]Rails: save file from URL and save it to Amazon S3
從給定的URL下載文件並立即將其上傳到Amazon S3的更直接的方法是什么(+將有關該文件的一些信息保存到數據庫中,如名稱,大小等)?
現在,我沒有使用Paperclip和Carrierwave。
謝謝
直截了當:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.