【问题标题】:Error with .webp images when using Active Storage on Heroku在 Heroku 上使用 Active Storage 时 .webp 图像出错
【发布时间】:2019-02-10 01:38:52
【问题描述】:

当我使用 Active Storage 时,当有人上传 .webp 图像时,当我运行 file.attach(io: webp_file, filename: 'file.webp') 时,它可以工作,然后 ActiveStorage 会自动运行作业 ActiveStorage::AnalyzeJob

但是这份工作提高了:

MiniMagick::Error (`identify -format %[orientation] /tmp/ActiveStorage-114989-20180905-4-wak8ob.webp[0]` failed with error:
identify-im6.q16: delegate failed `'dwebp' -pam '%i' -o '%o'' @ error/delegate.c/InvokeDelegate/1919.
identify-im6.q16: unable to open file `/tmp/magick-1400SWBHj-p67HrV': No such file or directory @ error/constitute.c/ReadImage/544.

虽然我在 Heroku-18 上,所以有一个名为“libwepb6”的库 (https://devcenter.heroku.com/articles/stack-packages) ????

我必须创建 Heroku buildpack 吗?

【问题讨论】:

    标签: ruby-on-rails heroku webp rails-activestorage


    【解决方案1】:

    遇到了同样的问题。这是一步一步的:

    1 - 将此添加到 development.rb 和 production.rb 以强制 rails 接受 WEBP。

    config.active_storage.variable_content_types = %w(
      image/png
      image/gif
      image/jpg
      image/jpeg
      image/webp
      image/vnd.adobe.photoshop
      image/vnd.microsoft.icon
    )
    

    2 - 将 this buildpack 添加到 heroku 上的应用程序,确保它是第一个包。它允许您安装尚未预装的 ubuntu 软件包。

    3 - 导航到应用的根目录(Gemfile 所在的位置)并运行以下命令以创建一个名为 AptFile 的文件,并将 webppackage 添加到其中。

    touch Aptfile
    echo "webp" >> Aptfile 
    

    4 - 重新部署您的应用。

    Heroku 现在将安装缺少的 webp 包,imagemagick 需要该包来处理 webp 图像。

    编辑:如果您使用的是 Rails 6.1 或更高版本,则不需要第 1 步。

    【讨论】:

    • 这非常适合我的应用程序。 rails_admin 并没有很好地工作,但是经过一些挖掘后,我意识到我必须将 webp 添加到这一行 github.com/sferik/rails_admin/blob/…。我把它留在这里,以防将来对其他人有所帮助。
    • 在 ubuntu 上,您列出的配置和安装 webp 对我有用 sudo apt-get install webp
    【解决方案2】:

    编辑:所以正在使用 S3 和 /tmp 进行操作。

    查看错误似乎委托给dwebp 很好,所以我必须假设它是正确构建的。如果它不是用 webp 构建的,你会得到一个像这样的委托错误

    identify.im6: no decode delegate for this image format `1.sm.webp' @ error/constitute.c/ReadImage/544.
    

    你可以通过运行heroku run "identify -list format | grep -i WebP"来确定

    错误似乎出在/tmp/ 文件目录访问上。 空间情况如何? df -h

    请注意,在 Mac 上我得到了这个,请注意 /var 目录的使用:

    ~/w/p ❯❯❯ identify 1.sm.webp
    Decoded /var/folders/lk/z_bvyjj939d94mvkx6rz9700fbx9gg/T/magick-99980zzj1IT0Lkx7L. Dimensions: 320 x 214 . Format: lossy. Now saving...
    Saved file /var/folders/lk/z_bvyjj939d94mvkx6rz9700fbx9gg/T/magick-999803WU_TvRo7xdJ
    1.sm.webp PAM 320x214 320x214+0+0 8-bit TrueColor sRGB 273989B 0.000u 0:00.000
    

    这位 heroku 员工可能会对此有所了解。

    本文还详细介绍https://devcenter.heroku.com/articles/active-storage-on-heroku,特别是这一点:

    虽然使用 :local 选项存储的文件上传会出现 刚开始工作时,附件会表现出看似奇怪的现象 行为并最终消失。

    建议使用云存储(例如 Amazon S3)。

    【讨论】:

    • 谢谢,我使用 Amazon S3,Active Storage 使用 tmp 文件处理文件,它适用于 .jpg、.png 但不适用于 .webp,我认为确实缺少一个库
    • 看起来问题与 imagemagick 在 Heroku 上支持的库有关。我现在正在平台上进行调查(我在那里工作)。 $heroku run bash; ~ $ curl https://www.gstatic.com/webp/gallery/1.sm.webp -O ~ $ identify 1.sm.webp identify-im6.q16: delegate failed 'dwebp' -pam '%i' -o '%o'' @ error/delegate.c/InvokeDelegate/1919.
    猜你喜欢
    • 2018-11-14
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 2019-01-26
    • 2018-12-26
    • 2020-04-30
    • 2018-11-16
    相关资源
    最近更新 更多