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

时间:2018-07-17 13:50:19

标签: 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

但是没有成功。我遇到No such file or directory错误。

你能帮我吗?谢谢!

1 个答案:

答案 0 :(得分:2)

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