Error with .webp images when using Active Storage on Heroku
Asked Answered
K

2

5

When I use Active Storage, and when someone upload a .webp image, and when I run file.attach(io: webp_file, filename: 'file.webp') it works, and then ActiveStorage automatically run a job ActiveStorage::AnalyzeJob

But this job raises :

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.

Although I am on Heroku-18, and so there is a lib called "libwepb6" (https://devcenter.heroku.com/articles/stack-packages) 🤔

Do I have to create a Heroku buildpack?

Kassandrakassaraba answered 5/9, 2018 at 2:11 Comment(0)
M
13

Had the same problem. Here's the step by step:

1 - Add this to development.rb and production.rb to force rails to accept 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 - Add this buildpack to your app on heroku, making sure it's the first pack. It allows you to install ubuntu packages that are not already preinstalled.

3 - Navigate to the root of your app (where your Gemfile is) and run the commands below to create a file named AptFile, and add the webppackage to it.

touch Aptfile
echo "webp" >> Aptfile 

4 - Redeploy your app.

Heroku will now install the missing webp package that imagemagick needs to handle webp images.

Edit: Step 1 is not necessary if you are on Rails 6.1 or later.

Matutinal answered 26/10, 2018 at 20:5 Comment(2)
This worked perfectly for my app. rails_admin did not work nicely however and after some digging I realized I had to add webp to this line github.com/sferik/rails_admin/blob/…. I'm leaving this here in case it helps others in the future.Harassed
on ubuntu, the configuration you listed and installing the webp works for me sudo apt-get install webpVita
D
-1

Edit: So S3 is being used and /tmp for manipulation.

Looking at the error it seems to delegate to dwebp fine, so I have to assume it was built correctly. If it wasn't built with webp you would get a delegate error like so

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

You can make sure by running heroku run "identify -list format | grep -i WebP"

The error seems to be on the /tmp/ file directory access. How's the space situation? df -h

Note that on a Mac I get this, notice the use of the /var directory:

~/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

Probably this heroku employee will shed more light on this.

This article also goes into detail https://devcenter.heroku.com/articles/active-storage-on-heroku, especially this point:

While file uploads that are stored with the :local option will appear to work at first, the attachments will exhibit seemingly strange behavior and eventually disappear.

with recommendations to use cloud storage (e.g. Amazon S3).

Divinadivination answered 5/9, 2018 at 4:4 Comment(2)
thank you, I use Amazon S3 and Active Storage uses tmp files for processing files, it works for .jpg, .png but not .webp, I think a library is really missingKassandrakassaraba
Looks like the issue has to do with the libraries that imagemagick supports on Heroku. I'm investigating now on the platform (I work there). $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.Staford

© 2022 - 2024 — McMap. All rights reserved.