Download and upload images via XHR API

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.