New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActiveStorage chokes on BMP data, raises ActiveStorage::InvariableError #35953
Comments
Here are the steps to reproduce this problem: $ rails c
Loading development environment (Rails 5.2.3)
2.6.1 :001 > path = Pathname.new(File.join('/Users/bparanj/Downloads/', 'w3c_home.bmp'))
=> #<Pathname:/Users/bparanj/Downloads/w3c_home.bmp>
2.6.1 :002 > io = path.open
=> #<File:/Users/bparanj/Downloads/w3c_home.bmp>
2.6.1 :003 > filename = 'w3c_home.bmp'
=> "w3c_home.bmp"
2.6.1 :004 > content_type = 'image/bmp'
=> "image/bmp"
2.6.1 :005 > ActiveStorage::Blob.create_after_upload! io: io, filename: filename, content_type: content_type, metadata: nil
Disk Storage (0.8ms) Uploaded file to key: HY23A2VzetwsgHf5qgzLxCaq (checksum: u81qf8b5juN4+dJjHb7fyQ==)
(0.1ms) begin transaction
ActiveStorage::Blob Create (0.3ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "metadata", "byte_size", "checksum", "created_at") VALUES (?, ?, ?, ?, ?, ?, ?) [["key", "HY23A2VzetwsgHf5qgzLxCaq"], ["filename", "w3c_home.bmp"], ["content_type", "image/bmp"], ["metadata", "{\"identified\":true}"], ["byte_size", 10422], ["checksum", "u81qf8b5juN4+dJjHb7fyQ=="], ["created_at", "2019-04-12 16:54:33.238697"]]
(0.6ms) commit transaction
=> #<ActiveStorage::Blob id: 1, key: "HY23A2VzetwsgHf5qgzLxCaq", filename: "w3c_home.bmp", content_type: "image/bmp", metadata: {"identified"=>true}, byte_size: 10422, checksum: "u81qf8b5juN4+dJjHb7fyQ==", created_at: "2019-04-12 16:54:33">
2.6.1 :007 > as = ActiveStorage::Blob.first
ActiveStorage::Blob Load (0.2ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" ORDER BY "active_storage_blobs"."id" ASC LIMIT ? [["LIMIT", 1]]
=> #<ActiveStorage::Blob id: 1, key: "HY23A2VzetwsgHf5qgzLxCaq", filename: "w3c_home.bmp", content_type: "image/bmp", metadata: {"identified"=>true}, byte_size: 10422, checksum: "u81qf8b5juN4+dJjHb7fyQ==", created_at: "2019-04-12 16:54:33">
2.6.1 :012 > as.variant(resize: "100x100")
Traceback (most recent call last):
2: from (irb):12
1: from (irb):12:in `rescue in irb_binding'
ActiveStorage::InvariableError (ActiveStorage::InvariableError) Sample bmp image used can be found here: https://www.w3.org/People/mimasa/test/imgformat/. The blob is not variable: 2.6.1 :013 > as.variable?
=> false According to the ImageMagick docs: https://imagemagick.org/script/formats.php. It supports bmp image. Currently ActiveStorage::Engine only supports: config.active_storage.variable_content_types = %w(
image/png
image/gif
image/jpg
image/jpeg
image/pjpeg
image/tiff
image/vnd.adobe.photoshop
image/vnd.microsoft.icon
) Don't know how to require the blob to create a test case, here is a minimal test case: 2.6.1 :005 > io = StringIO.new('test string')
=> #<StringIO:0x00007f8bb4661358>
2.6.1 :007 > content_type = 'image/bmp'
=> "image/bmp"
2.6.1 :008 > as2 = ActiveStorage::Blob.create_after_upload! io: io, filename: 'test.txt', content_type: content_type, metadata: nil
Disk Storage (1.1ms) Uploaded file to key: tug5y2JoVraQYrNCpTLHpoab (checksum: b421md6Yb6t6IWJbeRZYnA==)
(0.1ms) begin transaction
ActiveStorage::Blob Create (0.4ms) INSERT INTO "active_storage_blobs" ("key", "filename", "content_type", "metadata", "byte_size", "checksum", "created_at") VALUES (?, ?, ?, ?, ?, ?, ?) [["key", "tug5y2JoVraQYrNCpTLHpoab"], ["filename", "test.txt"], ["content_type", "image/bmp"], ["metadata", "{\"identified\":true}"], ["byte_size", 11], ["checksum", "b421md6Yb6t6IWJbeRZYnA=="], ["created_at", "2019-04-12 18:26:15.738431"]]
(0.6ms) commit transaction
=> #<ActiveStorage::Blob id: 2, key: "tug5y2JoVraQYrNCpTLHpoab", filename: "test.txt", content_type: "image/bmp", metadata: {"identified"=>true}, byte_size: 11, checksum: "b421md6Yb6t6IWJbeRZYnA==", created_at: "2019-04-12 18:26:15">
2.6.1 :009 > as2.variant(resize: "100x100")
Traceback (most recent call last):
1: from (irb):9
ActiveStorage::InvariableError (ActiveStorage::InvariableError)
2.6.1 :010 > Rails.version
=> "5.2.3" Ideally, Rails should throw an exception if bmp images are not supported. |
Use TIFF data with ActiveStorage (any variation - LZW-Compressed or not, Alpha or not) and call .variant on the data. See similar issue for TIFF at #34698
Steps to reproduce
Use BMP data with ActiveStorage and call .variant on the data
Expected behavior
Variant should be returned
Actual behavior
ActiveStorage::InvariableError is raised
System configuration
Rails version: 5.2
Ruby version: N/A
The text was updated successfully, but these errors were encountered: