Last active
March 5, 2018 15:00
-
-
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
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
// 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