Reputation: 3169
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?
Upvotes: 5
Views: 3263
Reputation: 2162
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 webp
package 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.
Upvotes: 13
Reputation: 360
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).
Upvotes: -1