如何使用离子框架在自定义文件夹中保存图像
从我的相机拍摄图像后,我想将其保存在我自己创建的文件夹中,请说clickImage文件夹
答案 0 :(得分:0)
为实现这一目标,我认为您需要将文件复制到本地存储。为此,您需要为copyFile使用文件插件。 请检查以下代码。我希望这对你有用。
angular.module('starter', ['ionic', 'ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
//you app code goes here
});
})
.controller('FileController', function($scope, $cordovaCamera, $cordovaFile) {
$scope.fileName = "";
$scope.uploadPicture = function() {
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 1024,
targetHeight: 768,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function(sourcePath) {
var sourceDirectory = sourcePath.substring(0, sourcePath.lastIndexOf('/') + 1);
var sourceFileName = sourcePath.substring(sourcePath.lastIndexOf('/') + 1, sourcePath.length);
console.log("Copying from : " + sourceDirectory + sourceFileName);
console.log("Copying to : " + cordova.file.dataDirectory + sourceFileName);
$cordovaFile.copyFile(sourceDirectory, sourceFileName, cordova.file.dataDirectory, sourceFileName).then(function(success) {
$scope.fileName = cordova.file.dataDirectory + sourceFileName;
}, function(error) {
console.dir(error);
});
}, function(err) {
console.log(err);
});
}
});
谢谢..