Skip to content

Instantly share code, notes, and snippets.

@sime
Created November 25, 2013 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sime/7641790 to your computer and use it in GitHub Desktop.
Save sime/7641790 to your computer and use it in GitHub Desktop.
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