Forked from robnyman/retrieve-indexeddb-file-create-object-url.js
Created
August 23, 2018 21:37
-
-
Save MaxWright/ff482fa1d1561efd9b150ab534184133 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