Ruby on rails 尝试使用ImageProcessing时出现未找到活动存储文件错误

Ruby on rails 尝试使用ImageProcessing时出现未找到活动存储文件错误,ruby-on-rails,image-processing,minimagick,Ruby On Rails,Image Processing,Minimagick,我一直在 ActiveStorage::FileNotFoundError (ActiveStorage::FileNotFoundError): app/models/service.rb:24:in `process_images' 尝试将图像加载到ImageProcessing::MiniMagick时使用 ImageProcessing::MiniMagick.source(self.image.download) 我也试过了 ImageProcessing::MiniMagick.s

我一直在

ActiveStorage::FileNotFoundError (ActiveStorage::FileNotFoundError):
app/models/service.rb:24:in `process_images'
尝试将图像加载到ImageProcessing::MiniMagick时使用
ImageProcessing::MiniMagick.source(self.image.download)

我也试过了

ImageProcessing::MiniMagick.source(self.image)
ImageProcessing::MiniMagick.source(self.image.attachment)
ImageProcessing::MiniMagick.source(self.image.attachment.download)
ImageProcessing::MiniMagick.source(self.image.blob)

ImageProcessing不喜欢这些,因为它在寻找url,所以我尝试使用url,就像这样
url=Rails.application.routes.url\u helpers.Rails\u blob\u path(self.image,only\u path:true)
并将其传入,而不是self.image 当我这样做的时候,我得到了错误

failed with error:
convert: unable to open image `rails/active_storage/blobs/foo...`
有人能给我指引正确的方向吗

这是我的模型的相关部分,就像现在看起来的一样

class Service < ApplicationRecord
  has_one_attached :image, dependent: :destroy
  has_one_attached :featured_image, dependent: :destroy

  after_create :process_images
  after_save :process_images

  private  
  def process_images 
    url = Rails.application.routes.url_helpers.rails_blob_path(self.image, only_path: true)
    pipeline1 = ImageProcessing::MiniMagick.source(url)
    #can't continue until I load an image
  end
end
类服务
我还从控制器调用了该方法。我将model方法设置为非私有并调用它,它解决了nil附件问题。下面是一个错误,但是我得到了这个错误。
ArgumentError(字符串包含空字节):
标记在此行。 pipeline1.将_调整为_限制(400400)。转换(“jpg”)。调用


我所要做的就是在创建或更新实例时调整图像大小,然后将处理后的图像保存为主附件。

根据文档“源对象需要响应
.path
,或者是
字符串
路径名
,或者
Vips::image/MiniMagick::Tool对象
”,您提供的参数都不符合要求

我的方法是获取ActiveStorage文件的完整路径,为此,我们可以使用
ActiveStorage::Blob.service.send(:path_for,)
,然后在
ImageProcessing::MiniMagick.source
方法中将其用作参数

这就是为什么以下方法有效:

ImageProcessing::MiniMagick.source(ActiveStorage::Blob.service.send(:path_for, self.image.key))

你能试试这个吗<代码>图像处理::MiniMagick.source(ActiveStorage::Blob.service.send(:path_for,self.image.key))
Patricio感谢您的帮助。如果你有空的话,你能解释一下为什么这个传递图像源的方法有效,而其他方法都无效吗?我写了一个答案来解释。在Rails 6.0.3.3上,我得到了这个错误:NoMethodError(未定义的方法'path_for'for#):@IvanRaszl嗯,看起来你使用的是S3 bucket,所以它无论如何都不起作用。