Skip to content

blobToUrl()

If urlOrBlob is already a string, returns it unchanged. If it is a Blob, returns URL.createObjectURL(blob) — a short-lived blob: URL valid in this document until URL.revokeObjectURL is called.

Pair with renderImage or <img src> without re-fetching binary data. Remember to revokeObjectURL when the URL is no longer needed to avoid retaining blob memory.

Examples:

ts
const src = blobToUrl(uploadedFile);
img.src = src;
// when done:
URL.revokeObjectURL(src);
ts
blobToUrl('https://cdn.example.com/logo.png'); // passed through as-is

Released under the MIT License.