Forked from robnyman/retrieve-indexeddb-file-create-object-url.js
Created
May 28, 2018 17:28
-
-
Save gabouh/ff639fbf50f723e966fe8ea8c775fffc to your computer and use it in GitHub Desktop.
Retrieve stored file from IndexedDB and create an ObjectURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retrieve the file that was just stored | |
transaction.objectStore("elephants").get("image").onsuccess = function (event) { | |
var imgFile = event.target.result; | |
console.log("Got elephant!" + imgFile); | |
// Get window.URL object | |
var URL = window.URL || window.webkitURL; | |
// Create and revoke ObjectURL | |
var imgURL = URL.createObjectURL(imgFile); | |
// Set img src to ObjectURL | |
var imgElephant = document.getElementById("elephant"); | |
imgElephant.setAttribute("src", imgURL); | |
// Revoking ObjectURL | |
URL.revokeObjectURL(imgURL); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment