Created
November 25, 2013 14:14
-
-
Save sime/7641790 to your computer and use it in GitHub Desktop.
storing photos from camera
This file contains hidden or 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
if (window.resolveLocalFileSystemURI) { | |
console.log('Attemping to resolveFileSystemURI of ' + imageData); | |
window.resolveLocalFileSystemURI( | |
imageData, | |
function(fileEntry) { | |
console.log('requesting file system'); | |
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) { | |
console.log('moving file'); | |
fs.root.getDirectory('bob', {create: true}, function(dirEntry) { | |
var fileName = moment().valueOf().toString() + '.jpg'; | |
fileEntry.moveTo(dirEntry, fileName, | |
function(newFileEntry) { | |
var newURI = newFileEntry.fullPath; // toURL(); | |
console.log('File.fullPath: ' + newFileEntry.fullPath); | |
console.log('File.toURL(): ' + newFileEntry.toURL()); | |
console.log('successfully moved file to: ' + newURI); | |
console.log('saving ' + newURI); | |
var photos = JSON.parse(window.localStorage.getItem("photos")); | |
console.log('extracted photos from localStorage'); | |
var key = new Date().valueOf(); | |
console.log('key name: ' + key); | |
var photo = {key: newURI}; | |
console.log('Prepping localStorage'); | |
window.localStorage.setItem("photos", JSON.stringify(photo)); | |
window.localStorage.setItem("photo", newURI); | |
console.log('fileEntry.moveTo() finished'); | |
}, | |
function() { | |
console.log('move failed of ' + fileName); | |
} | |
); | |
}, function(error) { | |
console.log('Could not get directory, error: #' + error.code); | |
}); | |
}, function(evt) { | |
console.log('requestFileSystem Failed'); | |
}); | |
}, | |
function(error) { | |
console.log('resolveLocalSystemURI FileError code: ' + error.code + ' ' + photos[i] + '@' + i); | |
} | |
); // window.resolveLocalFileSystemURI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment