【问题标题】:Uploaded images to cloudinary saves the images three times in my cloud storage将图像上传到 cloudinary 将图像保存在我的云存储中三次
【发布时间】:2019-04-30 02:28:48
【问题描述】:

请我在将图像上传到我的云存储(Cloudinary)时遇到这个问题。 当我在我的 Rails 应用程序中上传单个图像时,它会在我的云存储中重复 3 次。

我正在使用带有回形针云的 ruby​​ 2.3 和 Rails 5.1 ~> 1.3', '>= 1.3.2

我很确定我设置的路径。 我不知道如何设置正确的路径。

:path => ':class/:id/:style/:filename'

我的帖子模型

class Post < ApplicationRecord
    acts_as_votable
    belongs_to :user
    has_many :comments

    has_attached_file :image, 
    :storage => :cloudinary,
    :path => ':class/:id/:style/:filename',
    styles: { medium: "700x500#", small: "350x250>" }
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end

【问题讨论】:

  • 我可能会保存调整为 700x500、2350x250 和原始版本的图像。这有什么问题?
  • @spickermann 请这不是我问的问题。我的问题是,当我从我的 rails 应用程序将单个图像上传到云时,图像在我的云存储中显示为 3。我的意思是它变成了三胞胎

标签: ruby-on-rails ruby


【解决方案1】:

问题是路径中的 :style

:path => ':class/:id/:style/:filename'

为防止重复定义的样式,请从路径中删除样式选项

变成这样 =>

:path => ':class/:id/:filename'

【讨论】:

    【解决方案2】:

    这不是重复的图像。这是您在样式中提到的三个不同尺寸的图像。

    第一个是您实际上传的原始图像。

    第二个和第三个分别是中号:“700x500#”,小号:“350x250”。

    你可以称其他两个为原图的缩略图。

    【讨论】:

      猜你喜欢
      • 2019-08-15
      • 2015-05-19
      • 2021-10-28
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 2021-03-20
      • 1970-01-01
      • 2021-04-21
      相关资源
      最近更新 更多