复制应用程序文件夹中的文件

时间:2016-10-27 08:02:39

标签: javascript html css angularjs

我在一个项目上工作,此刻我结束了。我有一个系统,允许恢复图库android中的图像,然后查看和上传PHP服务器,如果用户决定。

代码

$scope.upload_media_file = function (file_uri, media_type, source) {
    alert('A upload');


    //Grab the file name of the photo in the temporary directory
    var currentName = file_uri.replace(/^.*[\\\/]/, '');

    //Creer un nouveau nom pour le fichier
    var date = new Date();
    var new_file_name = '';

    if (media_type === 'PICTURE') {
        var new_file_name = date.getTime() + '.jpg';
    }
    else if (media_type === 'VIDEO') {
        var new_file_name = date.getTime() + '.mp4';
    }


    //upload_file(nehmiRestApiBasicLink, new_file_name, file_location);
    // Si le fichier est recupere dans la bibliotheque d'android, on en fait un traitement special
    if ($cordovaDevice.getPlatform() == 'Android' && source === 1) {

        alert('Android upload');

        window.FilePath.resolveNativePath(file_uri, function (entry) {
            window.resolveLocalFileSystemURL(entry, success, fail);

            function fail(e) {
                console.error('Error: ', e);
            }

            function success(fileEntry) {
                var namePath = fileEntry.nativeURL.substr(0, fileEntry.nativeURL.lastIndexOf('/') + 1);

                $cordovaFile.copyFile(namePath, fileEntry.name, cordova.file.dataDirectory, new_file_name).then(function (success) {
                    var file_location = get_multimedia_url(new_file_name);

                    alert('copie avec success ' + success);

                    //Envoyer l'image ou ;a video sur le serveur
                    upload_file(nehmiRestApiBasicLink, new_file_name, file_location);

                }, function (error) {
                    alert('Erreur');
                });
            }
        });
    }
    else {

        var namePath = file_uri.substr(0, file_uri.lastIndexOf('/') + 1);
        // Move the file to permanent storage
        $cordovaFile.moveFile(namePath, currentName, cordova.file.dataDirectory, new_file_name).then(function (success) {

            alert('Succes non librairie');
            var file_location = $scope.get_multimedia_url(new_file_name);

            upload_file(nehmiRestApiBasicLink, new_file_name, file_location);

            //$scope.image = new_file_name;
        }, function (error) {
            alert('Erreur non libr');
        });
    }
}

运行警告说文件已成功复制,但是当我查看应用程序文件夹时,它是空的。有人可以帮我解决这个问题吗?

0 个答案:

没有答案