Ruby gems
mini_exiftool (metadata extractor)
mini_magick (convert .heic files > .jpeg)
mini_exiftool
requires Exiftool to be locally installed
This gems results are possibly just “EXIF” category metadata, but it might be multiple categories of metadata put together, as mini_exiftool says it can read/write EXIF-data, IPTC-data and XMP-data
to see all available metadata fields for a file ran through mini_exiftool, place the following code in company_files_controller:
# company_files_controller
# within :create action (within "if file_params[:attachments] ... end" block)
# read and log metadata (use this when wanting to see available metadata fields on an attachment)
file_params[:attachments].each do |attachment|
read_and_log_metadata(attachment)
end
# private method
def read_and_log_metadata(attachment)
begin
file = attachment.tempfile
puts "Reading file: #{file.path}"
puts "Using Exiftool command: #{MiniExiftool.command}"
if File.readable?(file.path)
metadata = MiniExiftool.new(file.path)
metadata.to_hash.each do |key, value|
puts "#{key}: #{value}"
end
puts "Metadata errors: #{metadata.errors.join(', ')}" unless metadata.errors.empty?
else
puts "File not readable: #{file.path}"
end
rescue => e
Rails.logger.error "Error reading metadata for file #{attachment.original_filename}: #{e}"
end
end
mini_magick
requires imagemagick to be locally installed
Last updated