-----update------
After some investigation, I found that commenting out
window.URL.revokeObjectURL( imgSrc );
fixed the issue in all browsers. It seems like Chrome was revoking the URL too early. I am curious to understand why this behavior occurs, and if there are any potential drawbacks to how I am currently handling the URL revocation process. Now, I revoke the previous URL as a new one is loaded using if (imgSrc) {window.URL.revokeObjectURL( imgSrc );}
(imgSrc is now a global variable).
I have a website that uses AJAX to communicate with a CGI script, which generates image/jpeg data. The blob response is then set as the source of an image on the webpage using the createObjectURL function. This functionality works smoothly in all browsers except for Chrome.
In other browsers, the image loads successfully, but in Chrome, I encounter the error message:
Failed to load resource: the server responded with a status of 404 (Not Found)
, followed by a URL starting with blob:
.
I attempted to use webkitURL as an alternative, but it resulted in the same error message along with webkitURL is deprecated
.
Here is the code snippet from my AJAX call:
var filepath = "/babelia.cgi";
xmlhttp=new XMLHttpRequest();
xmlhttp.onload = function(oEvent) {
if (imgSrc) {window.URL.revokeObjectURL( imgSrc );}
var blob = xmlhttp.response;
if (endless) {
imgSrc = (window.URL ? URL : webkitURL).createObjectURL( blob );
document.getElementById("palette").src = imgSrc;
// window.URL.revokeObjectURL( imgSrc );
babel();
}
}
xmlhttp.open("POST",filepath,true);
xmlhttp.responseType = "blob";
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var info = "location=" + postdata;
if (!landscape) {info += "&flip=portrait";}
xmlhttp.send(info);
You can view the website here: