Note that there are some explanatory texts on larger screens.

plurals
  1. POShow video blob after reading it through AJAX
    primarykey
    data
    text
    <p>While I was trying to create a workaround for Chrome unsupporting blobs in IndexedDB I discovered that I could read an image through AJAX as an arraybuffer, store it in IndexedDB, extract it, convert it to a blob and then show it in an element using the following code:</p> <pre><code>var xhr = new XMLHttpRequest(),newphoto; xhr.open("GET", "photo1.jpg", true); xhr.responseType = "arraybuffer"; xhr.addEventListener("load", function () { if (xhr.status === 200) { newphoto = xhr.response; /* store "newphoto" in IndexedDB */ ... } } document.getElementById("show_image").onclick=function() { var store = db.transaction("files", "readonly").objectStore("files").get("image1"); store.onsuccess = function() { var URL = window.URL || window.webkitURL; var oMyBlob = new Blob([store.result.image], { "type" : "image\/jpg" }); var docURL = URL.createObjectURL(oMyBlob); var elImage = document.getElementById("photo"); elImage.setAttribute("src", docURL); URL.revokeObjectURL(docURL); } } </code></pre> <p>This code works fine. But if I try the same process, but this time loading a video (.mp4) I can't show it:</p> <pre><code>... var oMyBlob = new Blob([store.result.image], { "type" : "video\/mp4" }); var docURL = URL.createObjectURL(oMyBlob); var elVideo = document.getElementById("showvideo"); elVideo.setAttribute("src", docURL); ... &lt;video id="showvideo" controls &gt;&lt;/video&gt; ... </code></pre> <p></p> <p>Even if I use xhr.responseType = "blob" and not storing the blob in IndexedDB but trying to show it immediately after loading it, it still does not works!</p> <pre><code>xhr.responseType = "blob"; xhr.addEventListener("load", function () { if (xhr.status === 200) { newvideo = xhr.response; var docURL = URL.createObjectURL(newvideo); var elVideo = document.getElementById("showvideo"); elVideo.setAttribute("src", docURL); URL.revokeObjectURL(docURL); } } </code></pre> <p>The next step was trying to do the same thing for PDF files, but I'm stuck with video files!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload