-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44f8816
commit c906137
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
set main=./examples/localforage/file-blob.js | ||
cd .. | ||
cd .. | ||
npm run watch |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import localforage from 'localforage'; | ||
|
||
localforage.getItem('photo').then(function (image) { | ||
if (!image) { | ||
return; | ||
} | ||
|
||
console.log('Load from localforage', image) | ||
}) | ||
|
||
var req = new XMLHttpRequest(); | ||
req.addEventListener('readystatechange', function () { | ||
if (req.readyState === 4) { // readyState DONE | ||
localforage.setItem('photo', req.response).then(function (image) { | ||
console.log('Load from request', image) | ||
|
||
// This will be a valid blob URI for an <img> tag. | ||
// var blob = new Blob([image]); | ||
// var imageURI = window.URL.createObjectURL(blob); | ||
|
||
}).catch(function (err) { | ||
// This code runs if there were any errors | ||
console.log(err); | ||
}); | ||
} | ||
}); | ||
req.open('GET', 'assets/images/mushroom.png'); | ||
req.responseType = 'arraybuffer'; | ||
req.send(); | ||
|
||
|