I'd recommend posting an easily reproducible example and a clear description of
what's happening (i.e. don't just say something doesn't work), it'll make it
easier for people to help you quickly.
This seems to work fine:
import std/[httpclient, uri, mimetypes, strformat]
let
url =
"https://www.gravatar.com/avatar/bd9201e3d43978e1f9a51ee7bc902312?s=80&d=identicon"
host = parseUri(url)
client = newHttpClient(headers=newHttpHeaders({"Referer": $host}))
rq = client.get(url)
suffix = newMimetypes().getExt(rq.headers["Content-Type"])
writeFile("index.html", "<img src='" & getDataUri(rq.body,
&"image/{suffix}") & "' />")
Run
If you open the generated index.html file you can see the image was encoded
successfully.