0

有没有办法从 URL 创建一个对象/ 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 来自剪贴板

4

1 回答 1

1

这是一个开始,它应该回答您指定的第一个 url。

请参阅https://developer.mozilla.org/en-US/docs/Web/API/Blobhttps://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);

见控制台:http: //jsfiddle.net/Seandeburca/P9HRa/

于 2013-09-09T08:52:23.250 回答