Adding unique colors to Metadata

I am trying to add the number of unique colors of an image to the metadata of the Shrine attachment.

I am successful in console at retrieveing this information with :

require 'mini_magick'
MiniMagick::Image.open("/home/maxence/Desktop/test images/test.jpg")["%k"] 

Though in my Shrine uploader as follow :

require "image_processing/vips"
require "image_processing/mini_magick"
require "mini_magick"

class SmallerUploader < Shrine	

add_metadata :unique_colors do |io|
    	minimagick_image = MiniMagick::Image.open(io)	
    	minimagick_image["%[k]"]
end

I get error : NoMethodError: undefined method `[]’ for #<File:/tmp/image_processing20210616-20690-6mavs4.jpg>

Though when playing with my variable minimagick_image through ByeBug I can retrieve the unique colors information.

Not sure what is wrong…

All good.
I have been able to do it outside the Uploader, in the Sidekiq Job :

minif = MiniMagick::Image.open(@image.image)
@image.image_attacher.add_metadata("quality": minif.data["quality"])
@image.image_attacher.add_metadata("color": minif["%[k]"])
@image.save
@image.reload