loading

Create a URL from C# bytes

Create

Create builds a Blob from your bytes (with the MIME type you pass) and returns its blob: URL. The URL is origin-scoped and works anywhere a regular URL does: anchors, images, iframes, downloads. Type some text, create a URL for it, then open or download the result.

C#
byte[] bytes = Encoding.UTF8.GetBytes("Hello from Bit.Butil!");

string url = await objectUrls.Create(bytes, "text/plain");

// <a href="@url" target="_blank">Open</a>
// <a href="@url" download="note.txt">Download note.txt</a>
Live sample
Text for the blob
create output
Results will appear here when you interact with the samples.

Render an image built in C#

Create

Any MIME type works. Here an SVG document is composed as a plain C# string, turned into an object URL with the image/svg+xml type and rendered by a regular img tag - no server, no data URL inflation.

C#
var svg = $"<svg xmlns='http://www.w3.org/2000/svg' width='240' height='120'>" +
          $"<rect width='240' height='120' rx='12' fill='#4f46e5'/>" +
          $"<text x='120' y='68' text-anchor='middle' fill='#fff' font-size='18'>Made at {DateTime.Now:HH:mm:ss}</text>" +
          "</svg>";

string url = await objectUrls.Create(Encoding.UTF8.GetBytes(svg), "image/svg+xml");
Live sample
image output
Results will appear here when you interact with the samples.

Revoke a URL

Revoke

Each object URL pins its Blob in memory until the document unloads or the URL is revoked. Revoke as soon as a URL is no longer referenced - after the download started or the image loaded. Revoking invalidates the URL immediately: links created above stop working.

C#
await objectUrls.Revoke(url);
Live sample
revoke output
Results will appear here when you interact with the samples.

Lifetime and automatic cleanup

Create(track) / DisposeAsync

ObjectUrls tracks every URL it creates and revokes any still outstanding when the service is disposed (end of circuit or app scope), so forgotten URLs don't leak. Pass track: false when a URL must outlive the service - then revoking it becomes your responsibility.

C#
// tracked (default): auto-revoked on DisposeAsync if you forget
string tracked = await objectUrls.Create(bytes, "application/pdf");

// untracked: survives disposal; call Revoke yourself
string longLived = await objectUrls.Create(bytes, "application/pdf", track: false);
Note:
Object URLs are per-document A blob: URL only resolves inside the document that created it. It cannot be persisted, shared with other tabs or sent to a server - treat it as a short-lived, in-page handle to bytes you already have.

API reference

Member
Signature
Description
Create
ValueTask<string> Create(byte[] data, string mimeType = "application/octet-stream", bool track = true)
Creates an object URL from raw bytes plus an optional MIME type. Tracked URLs are auto-revoked on disposal.
Revoke
ValueTask Revoke(string objectUrl)
Revokes a previously created object URL, releasing the underlying Blob.
DisposeAsync
ValueTask DisposeAsync()
Revokes every still-outstanding tracked URL created by this instance.
An unhandled error has occurred. Reload 🗙