Skip to content

Instantly share code, notes, and snippets.

@jguix
Last active March 5, 2018 15:00
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 jguix/491388be80a66695d429 to your computer and use it in GitHub Desktop.
Save jguix/491388be80a66695d429 to your computer and use it in GitHub Desktop.
Capture photo in an Ionic app and move the photo to permanent storage
// From: http://www.joshmorony.com/store-camera-photos-permanently-using-phonegap-ionic-ngcordova/
$cordovaCamera.getPicture(options).then(function(imagePath){
//Grab the file name of the photo in the temporary directory
var currentName = imagePath.replace(/^.*[\\\/]/, '');
//Create a new name for the photo
var d = new Date(),
n = d.getTime(),
newFileName = n + ".jpg";
//Move the file to permanent storage
$cordovaFile.moveFile(cordova.file.tempDirectory, currentName, cordova.file.dataDirectory, newFileName).then(function(success){
//success.nativeURL will contain the path to the photo in permanent storage, do whatever you wish with it, e.g:
//createPhoto(success.nativeURL);
}, function(error){
//an error occured
});
}, function(error){
//An error occured
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment