0

Is there a way to create an object / blob object from URL like this:

blob:http://127.0.0.1:8888/4bd9114b-1adb-40ce-b55b-a38f803b849a

and like this: blob:111d6876-dc9c-4ec5-84a1-1004cae101b4

Here is the code I've tried so far:

    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();

But the response is always this.status is 0

Update:

The blob came from the clipboard

4
  • Could you be more specific and provide some examples. What is the initial data and what should the output look like? Commented Sep 9, 2013 at 8:21
  • Where do you get the blob from? Database, filesystem.. what you provided are (urlencoded) strings. Basically, you can turn anything into objects Commented Sep 9, 2013 at 8:27
  • @DanFromGermany The blob came from the clipboard, so its purely client-side. Commented Sep 9, 2013 at 8:52
  • Your code is right, your url is either invalid or doesn't exist Commented Sep 9, 2013 at 8:58

1 Answer 1

1

This is a start, it should answer for the first url you specified.

See https://developer.mozilla.org/en-US/docs/Web/API/Blob and 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);

See console: http://jsfiddle.net/Seandeburca/P9HRa/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.