I
I
Ivan Ivanov2022-03-26 22:03:32
Google Chrome
Ivan Ivanov, 2022-03-26 22:03:32

How to save images from BLOB?

Hello. The site gives all pictures as BLOB objects. How can I save them to disk in a normal format?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GrayHorse, 2022-03-26
@GrayHorse

function download(blob, name, url) {
    const anchor = document.createElement("a");
    anchor.setAttribute("download", name || "");
    const blobUrl = URL.createObjectURL(blob);
    anchor.href = blobUrl + (url ? ("#" + url) : "");
    anchor.click();
    setTimeout(() => URL.revokeObjectURL(blobUrl), 5000);
}

The third parameter is optional. You can, for example, add the original link, then it may come in handy - look in the download manager from where (from which link) the file was downloaded.
It will look something like this:
blob:https://imgur.com/11fb6df9-e45b-4acf-b3eb-60d5d4656747#https://i.imgur.com/X92aA5Y.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question