Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Use fetch() to request the image, check that the response succeeded, then call response.blob(). This works when the image is same-origin or its server permits your page’s origin through CORS. If you need to display an image but do not need its bytes, assigning its URL directly to an <img> is simpler.
Convert an image URL to a Blob
This browser example fetches an image, rejects HTTP error responses, checks that the returned content is an image, and gives you a Blob you can upload or process. Change the URL to one your page is allowed to fetch.
async function imageUrlToBlob(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Image request failed: ${response.status} ${response.statusText}`);
}
const contentType = response.headers.get("Content-Type") || "";
if (!contentType.toLowerCase().startsWith("image/")) {
throw new Error(`Expected an image, received: ${contentType || "unknown content type"}`);
}
return response.blob();
}
try {
const blob = await imageUrlToBlob("https://example.com/photo.jpg");
console.log(blob); // Blob with the response bytes and media type
} catch (error) {
console.error(error);
}
MDN’s Fetch API documentation shows checking the response status before consuming the body. Calling blob() reads the response body to completion and resolves to a Blob; its type is taken from the response’s Content-Type header. See MDN’s Response.blob() reference.
The content-type check is an application safeguard, not a guarantee that the file is a valid or safe image. Servers sometimes return an HTML error page with a successful status or an incorrect content type. If the image will be processed or accepted from untrusted sources, validate it further in the part of your system that handles the file.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors#1 Best Overall
Use the Blob for upload, processing, or display
Upload or process the Blob directly
If the next API accepts a Blob or a File, pass the Blob without making an object URL. For example, an upload endpoint can receive it in a FormData body:
const blob = await imageUrlToBlob("https://example.com/photo.jpg");
const formData = new FormData();
formData.append("image", blob, "photo.jpg");
const uploadResponse = await fetch("/api/images", {
method: "POST",
body: formData
});
if (!uploadResponse.ok) {
throw new Error(`Upload failed: ${uploadResponse.status}`);
}
Use the filename and endpoint expected by your application. The upload request is separate from downloading the source image, so handle errors for both requests.
Display it with a temporary object URL
An object URL lets an element such as <img> use the Blob as a URL. It is not the original image URL; it is a temporary reference managed by the browser.
const blob = await imageUrlToBlob("https://example.com/photo.jpg");
const objectUrl = URL.createObjectURL(blob);
const image = document.querySelector("#preview");
image.src = objectUrl;
// When the preview is removed and the user no longer needs the image:
image.removeAttribute("src");
URL.revokeObjectURL(objectUrl);
Each call to URL.createObjectURL() creates an object URL. Revoke it when the resource is no longer accessible or needed. Do not revoke it immediately after the image loads if the user still needs to view, save, open, or interact with it. The lifecycle guidance is in MDN’s blob: URL reference.
Rank #2
Understand the CORS requirement
For a cross-origin image, browser fetch() follows CORS rules. The image server must allow your page’s origin with an appropriate Access-Control-Allow-Origin response header. If it does not, the browser prevents your JavaScript from reading the response body. A URL working in the address bar does not prove that a page on another origin can fetch its bytes.
This is different from displaying a remote image. A browser may be able to render <img src="https://other-site.example/image.jpg"> without giving your script access to the image bytes. If you need a Blob for upload, inspection, or processing, display permission is not enough; the server must permit script access. See MDN’s CORS guide.
Why no-cors is not a workaround
Adding mode: "no-cors" does not grant access to a remote image. It produces an opaque response: JavaScript cannot read its body or headers, and calling blob() on that response yields a zero-byte Blob with an empty type. That Blob is not useful for obtaining the image. The Fetch API documentation explains opaque responses and the limits of no-cors: Using the Fetch API.
What to do when the image server does not allow CORS
- If you control the image server, configure it to allow the origin that hosts your page.
- If you do not control it, use a server-side endpoint you control to retrieve the image, subject to the remote host’s access rules. Your server can then return the bytes to your browser under your own origin.
- If you only need to show the image, use its remote URL directly in an image element instead of fetching it into a Blob.
A client-side proxy that merely forwards arbitrary URLs can create security and abuse risks. Restrict any server-side retrieval endpoint to the sources and use cases your application needs.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteChoose between fetching a Blob and using the image URL
| Need | Approach | Important condition |
|---|---|---|
| Upload, inspect, transform, or otherwise use image bytes in JavaScript | fetch(url), check response.ok, then call response.blob() |
The image must be same-origin or the server must permit your origin through CORS. |
| Show an image without reading its bytes | Set the remote URL as an image element’s src |
Displaying an image does not make its bytes available to JavaScript. |
| Give an image element a Blob you already fetched | Call URL.createObjectURL(blob) and set the result as src |
Revoke the object URL after the image is no longer needed. |
Or skip the browser setup
If your goal is to capture a webpage as an image or PDF rather than fetch an existing image file, ScreenshotNeo provides a screenshot API and MCP server. It is a different task from converting an image URL into a Blob: the API captures a page and returns an image or PDF response. Its one-request example is:
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://stripe.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) {
throw new Error(`Screenshot request failed: ${res.status}`);
}
const screenshotBlob = await res.blob();
See the ScreenshotNeo documentation for request options and response details. Cookie banners, newsletter popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for free and get 1,000 screenshots a month with no card.
Troubleshooting common failures
The browser reports a CORS error
The remote server has not granted your page access to read the response. You cannot repair that permission with JavaScript or no-cors. Ask the server owner to enable CORS, retrieve the image through a controlled server-side endpoint, or use the remote URL directly if you only need to display it.
The request returns an error status
A 404, 403, or another unsuccessful HTTP status still produces a Fetch response in many cases; it does not necessarily reject the promise. Check response.ok before calling blob(), as in the example, and handle the returned status. A network-level failure, by contrast, can reject fetch() itself.
Free tools Windows power users keep installed
One-click scans. No signup required.
The Blob is empty or has no type
Check whether the response is opaque, whether the requested URL actually returned a file, and what Content-Type the server sent. An opaque no-cors response cannot provide usable image bytes. A server may also return an empty response or omit or misstate its content type.
Rank #4
The Blob contains a web page instead of an image
A successful status alone does not establish that the response is an image. Inspect the response content type and the Blob’s type; a login page, bot challenge, or error document may have been returned instead. The example rejects non-image content types, but applications handling untrusted input may need stronger validation.
The image stops working after cleanup
If the object URL was revoked while the image or user still needed it, create a new object URL from the Blob and keep it alive for the required period. Revoke each object URL when its associated preview or other use has ended.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Performance and reliability notes
response.blob() consumes the response body to completion, so the complete image is available as a Blob only after the download finishes. Large images therefore take longer to fetch and require more memory than small ones. Avoid fetching an image as a Blob when a direct image URL meets the need, and avoid creating object URLs for content that does not need one.
Handle fetch and upload failures separately, set a timeout or cancellation policy appropriate to your application, and consider limits on acceptable file size and type. Browser code cannot override the remote server’s CORS policy. For repeatable access to third-party images, a server-side retrieval path can centralize permissions and validation, but it must respect the image host’s rules and protect your endpoint against arbitrary URL fetching.
Best Value
Frequently Asked Questions
Does response.blob() convert or re-encode an image?
No. It reads the response body into a Blob; it does not itself convert the image to a different format. The Blob’s type reflects the response’s Content-Type.
Can I use an image URL as a Blob without downloading it?
No. A Blob containing the image bytes requires those bytes to be available to your code. A direct <img> URL can display an image without providing those bytes to JavaScript.
Can I call URL.revokeObjectURL() as soon as an image loads?
Only if nothing still needs access to the object URL. Keep it available while the user or application still needs to view, save, open, or otherwise use the image.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

