1. Use the IMG tag in HTML to download images and download them via the XHR API:
1 varXHR =NewXMLHttpRequest ();2Xhr.open (' GET ', '/img/tooth-intro.jpg ');3Xhr.responsetype = ' blob ';//Binary Files4Xhr.onload =function(){5 if( This. Status = = 200){6 varimg = document.createelement (' img '));7img.src = window. Url.createobjecturl ( This. Response);8Img.onload =function(){9 //when the picture is loaded, release a URL resource. TenWindow. Url.revokeobjecturl ( This. src); One } A Document.body.appendChild (IMG); - } - } theXhr.send ();
2. You do not need to upload files and images through the form.
3.HXR can not meet the flow of data transmission, but there are other ways, but also specifically for the flow data processing and design.
server-sent Events provides a convenient streaming API for sending text data from the server to the client,
The websocket provides an efficient, bidirectional flow mechanism that supports both binary and file data.
Download and upload images via XHR API