image_processing: VipsForeignLoad: "/tmp/ActiveStorage-28657-20220112-4-8e2faa.jpg" is not a known file format

Bug report

Describe the bug

Somehow when trying to process an image I got this error:

VipsForeignLoad: "/tmp/ActiveStorage-28657-20220112-4-8e2faa.jpg" is not a known file format

To Reproduce

Steps to reproduce the behavior:

  1. user uploads an image
  2. I transform it using rails’s active storage attachment.file.variant(**options).processed
  3. See error

Expected behavior

Either says the file is not found somehow (maybe because of a server/dyno restart?) (I’m on Heroku), or maybe a missing package? not sure

Or actually process the file and return a new processed file

Actual behavior

Errors out

Environment

  • OS: (uname -a) Linux c5450f47-0d17-4a40-8f95-2c64a40e8e2c 4.4.0-1097-aws #102-Ubuntu SMP Fri Sep 10 22:18:30 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • Vips: I can’t seem to find it, it’s on Heroku, I used an Aptfile to install libvips, probably the latest on the latest stable version of ubuntu

Additional context

I’m on a rails app, users can upload images, I process them (size, remove filenames, remove metadata, optimize, etc.)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (3 by maintainers)

Most upvoted comments

Why would an ActiveStorage::Blob.download return "" Does this means the file was not uploaded?

This is how the blob record looks like

#<ActiveStorage::Blob:0x00007fcffec70170
 id: 9175,
 key: "cyrlrcoiotkfyzhn923dz1elpm",
 filename: "Image.jpeg",
 content_type: "image/jpeg",
 metadata: {"identified"=>true, "analyzed"=>true},
 service_name: "amazon",
 byte_size: 0,
 checksum: "1B2M2Y8AsgTpgAmhCfg==",
 created_at: Tue, 20 Sep 2022 00:42:27.524396000 UTC +00:00>

When you try to read the same file with vips you get this issue.

 photos.first.blob.open do |file|
   Vips::Image.new_from_file file.path
 end

Error:

/Users/gathuku/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/ruby-vips-2.1.4/lib/vips/image.rb:281:in `new_from_file': VipsForeignLoad: "/var/folders/ch/8_2mrh555z9_19b8lzgkf44c0000gp/T/ActiveStorage-9175-20220926-91104-3ubaml.jpeg" is not a known file format (Vips::Error)

Yes, that’s expected behaviour. I think we used to special-case zero length files and have a different error message, but we removed it for simplicity.

Would you prefer a special message for this?

For those who land on this issue looking for a solution:

Easiest option is to install libvips-dev so that it installs all the require dependancies. This will install all the required libraries to support all the major file formats.

$ sudo apt-get install libvips-dev

If you are building libvips from source you need to install the optional dependancies yourself before you install libvips. You will see in libvips install instructions that it has many optional dependancies: https://www.libvips.org/install.html.

Pick the libraries required for the file formats you want to support or almost all of them with the following before you try to build from source. The following will install support for all major formats.

$ sudo apt-get install libjpeg-turbo8-dev \
                     libexif-dev \
                     libgif-dev \
                     librsvg2-dev \
                     libpoppler-glib-dev \
                     libtiff-dev \
                     libfftw3-dev \
                     libpng-dev \
                     liborc-0.4-dev \
                     libcfitsio-dev \
                     libwebp-dev \
                     libnifti-dev \
                     libheif-dev \
                     libopenslide-dev \
                     libgsf-1-dev \
                     libopenexr-dev \
                     libmatio-dev \
                     libmagickcore-dev \
                     libmagickwand-dev \
                     libimagequant-dev

@janko Here is a sample app: https://github.com/tsrivishnu/tmp-rails-libvips-jpg-failures that you can run in docker. The README has the instructions to run it in Docker. Make sure you adapt the Dockerfile as in the first point under Setup. Let me know if you are able to reproduce it.