使用活动存储映像获取 MD5 哈希值

Pro*_*z1g 5 ruby-on-rails ruby-on-rails-5 rails-activestorage ruby-on-rails-5.2

在更新到 Rails 5.2 之前,我通过回形针图像创建了 MD5 哈希值,如下所示:json.image_md5 Digest::MD5.file(monument.image.path(:mobile)).hexdigest

现在,有了 Active Storage,我该如何做同样的事情呢?我已经尝试过了:

json.image_md5 Digest::MD5.file(url_for(monument.cover_image)).hexdigest
json.image_md5 Digest::MD5.file(rails_blob_path(monument.cover_image)).hexdigest
json.image_md5 Digest::MD5.file(Rails.application.routes.url_helpers.rails_blob_path(monument.cover_image, only_path: true)).hexdigest
Run Code Online (Sandbox Code Playgroud)

但没有成功。我收到一个错误No such file or directory

你能帮助我吗?谢谢你!

Geo*_*orn 7

Active Storage 计算文件的 Base64 编码 MD5 摘要,可通过monument.cover_image.checksum.