P粉0051346852023-08-24 14:48:24
You can also get the BLOB object directly from XMLHttpRequest. Just set responseType to blob. This is my code:
var xhr = new XMLHttpRequest(); xhr.open("GET", "http://localhost/image.jpg"); xhr.responseType = "blob"; xhr.onload = response; xhr.send();
The response function is as follows:
function response(e) { var urlCreator = window.URL || window.webkitURL; var imageUrl = urlCreator.createObjectURL(this.response); document.querySelector("#image").src = imageUrl; }
We just create an empty image element in HTML:
<img id="image"/>
P粉7425503772023-08-24 00:00:37
The problem is that I have hexadecimal data that needs to be converted to binary before Base64 encoding.
In PHP:
base64_encode(pack("H*", $subvalue))