Ruby on rails 打开错误的输出

Ruby on rails 打开错误的输出,ruby-on-rails,image,open-uri,cloudinary,Ruby On Rails,Image,Open Uri,Cloudinary,我正在尝试从web下载图像并将其上传回Cloudinary。我的代码适用于某些图像,但不适用于其他图像。我已将问题隔离到这一行(它需要打开uri): 因为,它工作得很好图像是 #<Tempfile:/var/folders/49/bmhbmmzj5fl31dm9j6m6gxr00000gn/T/open-uri20150526-7662-1b676ws> # cloudinary接受了这一点。然而,当我尝试拉动时,图像变为 #<StringIO:0x007fa0267c8f

我正在尝试从web下载图像并将其上传回Cloudinary。我的代码适用于某些图像,但不适用于其他图像。我已将问题隔离到这一行(它需要
打开uri
):

因为,它工作得很好<代码>图像是

#<Tempfile:/var/folders/49/bmhbmmzj5fl31dm9j6m6gxr00000gn/T/open-uri20150526-7662-1b676ws>
#
cloudinary接受了这一点。然而,当我尝试拉动时,图像变为

#<StringIO:0x007fa0267c8f80 @base_uri=#<URI::HTTP:0x007fa0267c92c8 URL:http://www.spiresources.net/WebImages/480/swatch/CELW.JPG>, 
@meta={"date"=>"Tue, 26 May 2015 22:17:47 GMT", "server"=>"Apache/2.2.22 (Ubuntu)", 
"last-modified"=>"Mon, 29 Jun 2009 00:00:00 GMT", "etag"=>"\"44700f-c35-46d715f090000\"", 
"accept-ranges"=>"bytes", "content-length"=>"3125", "content-type"=>"image/jpeg"}, @metas={"date"=>["Tue, 26 May 2015 22:17:47 GMT"], "server"=>["Apache/2.2.22 (Ubuntu)"], 
"last-modified"=>["Mon, 29 Jun 2009 00:00:00 GMT"], "etag"=>["\"44700f-c35-46d715f090000\""], "accept-ranges"=>["bytes"], 
"content-length"=>["3125"], "content-type"=>["image/jpeg"]}, @status=["200", "OK"]>
#“2015年5月26日星期二22:17:47 GMT”,“服务器”=>“Apache/2.2.22(Ubuntu)”,
“上次修改”=>“2009年6月29日星期一00:00:00 GMT”,“etag”=>“44700f-c35-46d715f090000\”,
“接受范围”=>“字节”,“内容长度”=>“3125”,“内容类型”=>“图像/jpeg”},@metas={“日期”=>[“周二,2015年5月26日22:17:47 GMT”],“服务器”=>[“Apache/2.2.22(Ubuntu)”,
“上次修改”=>[“2009年6月29日星期一00:00:00 GMT”],“etag”=>[“44700f-c35-46d715f090000\”],“接受范围”=>[“字节”],
“内容长度”=>[“3125”],“内容类型”=>[“图像/jpeg”]},@status=[“200”,“确定”]>

cloudinary拒绝并引发“StringIO未转换为字符串”错误。为什么
openuri
会为类似的图像返回不同的对象?如何使
openuri
返回
tempfile
或至少将
StringIO
转换为
tempfile

您只需将URL提供给Cloudinary上载方法即可。然后Cloudinary将直接获取远程资源

#<StringIO:0x007fa0267c8f80 @base_uri=#<URI::HTTP:0x007fa0267c92c8 URL:http://www.spiresources.net/WebImages/480/swatch/CELW.JPG>, 
@meta={"date"=>"Tue, 26 May 2015 22:17:47 GMT", "server"=>"Apache/2.2.22 (Ubuntu)", 
"last-modified"=>"Mon, 29 Jun 2009 00:00:00 GMT", "etag"=>"\"44700f-c35-46d715f090000\"", 
"accept-ranges"=>"bytes", "content-length"=>"3125", "content-type"=>"image/jpeg"}, @metas={"date"=>["Tue, 26 May 2015 22:17:47 GMT"], "server"=>["Apache/2.2.22 (Ubuntu)"], 
"last-modified"=>["Mon, 29 Jun 2009 00:00:00 GMT"], "etag"=>["\"44700f-c35-46d715f090000\""], "accept-ranges"=>["bytes"], 
"content-length"=>["3125"], "content-type"=>["image/jpeg"]}, @status=["200", "OK"]>