【问题标题】:Open URI Wrong Output打开 URI 错误输出
【发布时间】:2015-08-08 19:22:19
【问题描述】:

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

image = open(params[:product_image][:main])

对于this image,它工作正常。 image

#<Tempfile:/var/folders/49/bmhbmmzj5fl31dm9j6m6gxr00000gn/T/open-uri20150526-7662-1b676ws>

并且cloudinary 接受了这一点。但是,当我尝试拉this image 时,图像变为

#<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"]>

哪个 cloudinary 拒绝并引发“没有将 StringIO 转换为字符串”的错误。为什么open-uri 会为看起来相似的图像返回不同的对象?我怎样才能让open-uri 返回tempfile 或至少将我的StringIO 变成tempfile

【问题讨论】:

    标签: ruby-on-rails image open-uri cloudinary


    【解决方案1】:

    您可以简单地将 URL 提供给 Cloudinary 上传方法。然后 Cloudinary 将直接获取远程资源。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多