Skip to content

Instantly share code, notes, and snippets.

@sime sime/gist:7641790
Created Nov 25, 2013

Embed
What would you like to do?
storing photos from camera
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
You can’t perform that action at this time.