dragonfly
dragonfly copied to clipboard
Wrong mime type for image without filename
Apparently there's something weird with the mime_type method for an image:
binary_image = File.open('test/fixtures/files/image.png').read
image_uid = Dragonfly.app.store(binary_image)
image = Dragonfly.app.fetch(image_uid)
pry(main)> image.format
DRAGONFLY: shell command: 'identify' '-ping' '-format' '%m %w %h' '/var/folders/qc/c_sksnns54q13ympksl8x4h00000gp/T/dragonfly20160328-31715-tu2llz'
=> "png"
pry(main)> image.mime_type
=> "application/octet-stream"
but if I call
pry(main)> Dragonfly.app.mime_type_for(image.format)
=> "image/png"
I get the correct mime type.
It seems to me that https://github.com/markevans/dragonfly/blob/master/lib/dragonfly/content.rb#L81 should call mime_type_for(image.format) or at least have an option to call it because relying on the extensions won't always work (I noticed this behavior because I have image data in base64 or image data without an extension sometime).
I had the same problem and made a workaround with a processor like this
processor :force_extension do |content, *args|
content.ext = args[0]
end
It is used like this
attachment.force_extension('docx').url