Capturing and storing a picture taken with the Camera into a local database / PhoneGap / Cordova / iOS

前端 未结 5 1008
走了就别回头了
走了就别回头了 2020-11-27 03:45

I\'m currently building an app for iOS using Phonegap/Cordova and jQuerymobile. The idea is to take photos with camera and store the captured image for future use. I would l

5条回答
  •  轮回少年
    2020-11-27 04:18

    I just did a that works with promises, based on Jérôme's answer above:

    function moveFile(file){
    
        var deferred = $q.defer();
    
        window.resolveLocalFileSystemURL(file,
            function resolveOnSuccess(entry){
    
                var dateTime = moment.utc(new Date).format('YYYYMMDD_HHmmss');
                var newFileName = dateTime + ".jpg";
                var newDirectory = "photos";
    
                window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {
    
                        //The folder is created if doesn't exist
                        fileSys.root.getDirectory( newDirectory,
                            {create:true, exclusive: false},
                            function(directory) {
    
                                entry.moveTo(directory, newFileName, function (entry) {
                                    //Now we can use "entry.toURL()" for the img src
                                    console.log(entry.toURL());
                                    deferred.resolve(entry);
    
                                }, resOnError);
                            },
                            resOnError);
                    },
                    resOnError);
            }, resOnError);
    
        return deferred.promise;
    }
    
    function resOnError(error) {
        console.log('Awwww shnap!: ' + error.code);
    }
    

提交回复
热议问题