有没有办法从URL创建一个object / blob对象:
blob:http://127.0.0.1:8888/4bd9114b-1adb-40ce-b55b-a38f803b849a
并且像这样:blob:111d6876-dc9c-4ec5-84a1-1004cae101b4
这是我到目前为止尝试过的代码:
var xhr = new XMLHttpRequest();
xhr.open('GET', source, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
alert('Response status - ' + this.status);
if (this.status == 200) {
var myBlob = this.response;
alert("Converted to Blob");
}
};
xhr.send();
但响应总是this.status
是0
更新
blob来自剪贴板
答案 0 :(得分:1)
这是一个开始,它应该回答您指定的第一个网址。
参见https://developer.mozilla.org/en-US/docs/Web/API/Blob 和 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
var blobPart=["http%3A//127.0.0.1%3A8888/4bd9114b-1adb-40ce-b55b-a38f803b849a"];
var blob = new Blob(blobPart, {type: "application/octet-binary"}); // pass a useful mime type here
console.log("blob ~ ", blob);
var urlObj = URL.createObjectURL(blob);
console.log("url ~", urlObj);
//using FileReader to read Blob
var reader = new FileReader();
reader.addEventListener("loadend", function() {
console.log("reader result ~ ",reader.result);
});
reader.readAsDataURL(blob);