Home > Back-end >  JS download file
JS download file

Time:01-16

The function getBase64 (imgUrl) {
Window. The URL=window. URL | | window. WebkitURL;
Var XHR=new XMLHttpRequest ();
XHR. Open (" get ", imgUrl, true);
//vital
XHR. ResponseType="blob";
XHR. onl oad=function () {
If (this. Status==200) {
//get a blob object
Var blob=this. The response;
//the console. The log (" blob "blob);
//vital
Let oFileReader=new FileReader ();
OFileReader. onl oadend=function (e) {
//to get here is the picture of base64
Let base64=e. arget. Result;
Base64="& lt; P id="' Base64Text '& gt;" + base64 + "& lt;/p> ";
Document. The getElementsByTagName (" body ") [0]. InnerHTML=base64;
Return base64.
};
OFileReader. ReadAsDataURL (blob);
}
}
XHR. The send ();
}

I find such a JS code on the Internet, you can get the network file base64, can at first, but then don't know what is the limit, web developers do to can not get, is there any way to break through?

CodePudding user response:

There is no other way to download files, as long as they can return, regardless of the return is what type

CodePudding user response:

Each browser support is not the same as the degree of H5, file address can access URL can read, you can get by Java code,