我正在Ruby上使用Elastic Beanstalk编写一个应用程序,我从远程服务器下载文件并将其写入存储桶中的对象。
require 'open-uri'
...
s3 = AWS::S3.new
bucket = s3.buckets['mybucket']
f = open(params[:url]) #using open-uri
obj = bucket.objects[params[:key]]
obj.write[f] #<< fails here
然而,最后一行在日志中失败并出现以下异常:
:data must be provided as a String, Pathname, File, or an object that responds to #read and #eof?
但是,我知道,在我的计算机上执行相同的#open
时,f
是一个StringIO
对象,其中包含#read
和#eof?
答案 0 :(得分:0)
我在S3
上传zip文件时遇到同样的错误,最后这对我有用:
zip_data = File.read(zip_file_path)
表示,zip_data将是位于tmp目录中的zip文件路径的对象。
希望,这对你也有用。