Download an image or binary file and convert it to a blob or base64.
Code
Utilitiesconst response = await fetch('https://httpbin.org/image/png');
const blob = await response.blob();
// Convert to base64 data URL
const reader = new FileReader();
const dataUrl = await new Promise(resolve => {
reader.onload = () => resolve(reader.result);
reader.readAsDataURL(blob);
});
dataUrl;Browser·fetch() may be limited by CORS
Other Formats
// Get as ArrayBuffer for binary processing
const buffer = await response.arrayBuffer();
// Create object URL for display
const objectUrl = URL.createObjectURL(blob);
Available Test Images
https://httpbin.org/image/pnghttps://httpbin.org/image/jpeghttps://httpbin.org/image/svghttps://httpbin.org/image/webp
More JavaScript Snippets
Add Query Parameter
Add or update a query parameter in a URL string.
Bearer Token Authentication
Make an authenticated HTTP request using Bearer token for JWT or OAuth.
Check Cloudflare Cache Status
Check if a resource is served from Cloudflare's cache by inspecting the CF-Cache-Status header.
CORS Cross-Origin Request
Make a cross-origin HTTP request with CORS headers inspection.
Delayed Response (Test Timeouts)
Request a delayed response to test timeout handling with AbortController.
Fetch Error Details
Extract status, headers and body from an HTTP error response.