Kamel icon indicating copy to clipboard operation
Kamel copied to clipboard

Decide type of image not using URL extension

Open kolesnikov-pasha opened this issue 2 years ago • 6 comments

Some links could not have any extension and provide, for example, svg images. In this case, image won't be shown correctly.

Example of link: https://img.recraft.ai/k0Ksvp7ONUcklX29-XZ42n0cxZC4DkiR1UnHLgBHv0I/rs:fit:768:768:0/raw:1/plain/abs://staging/images/85e93fd8-a732-4cb6-aaac-45e9285a4aaf

kolesnikov-pasha avatar Dec 16 '23 23:12 kolesnikov-pasha

yeah, right now it depends on extensions to determine type. If you have any suggestions on how to determine type from the file itself that would be helpful.

luca992 avatar Dec 17 '23 20:12 luca992

The one thing I have in my mind is to

  1. check all caches for the key. If it is present then decide type based on cache type
  2. if no cached image for this key, download file and decide its type based on the content, I guess it shouldn't be hard (for example, svg files always start with <svg and so on)

I'll try to research this question and make PR later this week

kolesnikov-pasha avatar Dec 17 '23 21:12 kolesnikov-pasha

Maybe it is possible to use this tool or to port its part on Kotlin: https://imagemagick.org/script/identify.php

kolesnikov-pasha avatar Dec 17 '23 21:12 kolesnikov-pasha

HTTP Content-Type header could be a good source of information for this

eskatos avatar Jan 21 '24 23:01 eskatos

HTTP Content-Type header could be a good source of information for this

Yeah that could help for network requests 👍

luca992 avatar Jan 22 '24 00:01 luca992