Skip to content
Snippets Groups Projects
Verified Commit 7bbcaae0 authored by Pascal Ernster's avatar Pascal Ernster :mask:
Browse files

Add error handling for MiniMagick parsing uploaded "image" files

MiniMagick may fail for a variety of reasons, including "the file type
is not allowed in the ImageMagick security policy we use".

Instead of showing a "This file name is restricted. Delete this file
and upload again after changing the name" error message to the end user,
handle the situation gracefully and let the upload proceed without
adding image dimensions.

Solves https://gitlab.ruhr-uni-bochum.de/FDM/rdm-system/antleaf-projectmanagement/-/issues/428



Signed-off-by: default avatarPascal Ernster <pascal.ernster@rub.de>
parent dd6286ca
Branches
Tags
No related merge requests found
Pipeline #16959 canceled
......@@ -37,10 +37,13 @@ module Hyrax
def set_characterization_data
if file.file.content_type.include?('image')
image = MiniMagick::Image.open(file.path)
self.characterization_data[:height] = image[:height]
self.characterization_data[:width] = image[:width]
begin
image = MiniMagick::Image.open(file.path)
self.characterization_data[:height] = image[:height]
self.characterization_data[:width] = image[:width]
rescue
Rails.logger.info "Detected image MIME type, but MiniMagick failed to open or parse file \"#{file.file.original_filename}\"."
end
end
self.characterization_data[:content_type] = Marcel::Magic.by_path(file.path).to_s
......@@ -58,4 +61,4 @@ module Hyrax
end
end
end
end
\ No newline at end of file
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment