One other option would be storing your images and other formats as “unixfs objects”. The nide thing about this is that if you view the content over a gateway, the gateway will do mime-type detection and enable serving the content via the gateway.
For go-ipfs you can use the ipfs add command. I dont personally use js-ipfs so I’m not 100% sure what the equivalent command would be, but it should be something like add, addFromFS and there may be one other one.
In the case of the js-ipfs-http-client package it’s instanceOfAPIClient.add, and insanceOfAPIClient.addFromFS
But you’re not really getting any of the benefits of IPFS here as the image is being served over HTTP.
There’s also a caveat that the gateway is a shared public resource and not one that you should rely on to power your app, instead you should set up your own gateways.
I mean if you’re using a remote gateway sure, but you can always use a local gateway on your laptop or whatever. Gateways have their uses, locally, or publicly; A gateway isn’t an exclusively public resource unless you make it.
The API seems to have changed. Trying to apply this exact code to an svg stored on IPFS seems to corrupt the data, while retrieving from the gateway works fine.