ionic FileTransfer不给出结果/错误/反馈,然后做成功函数

ionic FileTransfer gives no result/errors/feedback, and then does do the success function

本文关键字:然后 成功 函数 反馈 错误 结果 ionic FileTransfer      更新时间:2023-09-26

我有一个Ionic框架,在那里我有FileTranser模块加载,所以我可以拍照并上传。"拍照"部分效果很好。

当我点击图片时,它会上传,它会触发叠加"正在上传",然后淡出,它会完成oncomplete功能。

问题是实际的上传部分什么也没做。没有错误,没有通知,日志中没有任何内容,没有实际的XHR资源(或任何资源)。这使得它很难调试。谁能给我指一下正确的方向?

Ps:我在我的android上做这个,连接到Chrome的debugconsole

$scope.takePicture = function() {
    var options = {
        quality: 90,
        destinationType: Camera.DestinationType.FILE_URL,
        sourceType: Camera.PictureSourceType.CAMERA
    };
    $cordovaCamera.getPicture(options).then(
        function(imageData) {
            $scope.picData = imageData;
            $scope.ftLoad = true;
            //~ $localStorage.setItem('fotoUp', imageData);
            //~ $localStorage.fotoUp = imageData;
            $ionicLoading.show({template: 'Loading picture...', duration:500});
        },
        function(err){ 
            $ionicLoading.show({template: 'Error loading...', duration:500});
        }
    )
}
//--------------------------
// Upload the photo
$scope.uploadPicture = function() {
    $scope.upload = {};
    $ionicLoading.show({template: 'Bezig met uploaden...'});
    var fileURL = $scope.picData;
    var options = new FileUploadOptions();
    options.fileKey = "file";
    options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
    options.mimeType = "image/jpeg";
    options.chunkedMode = true;

    var ft = new FileTransfer();
    ft.upload(fileURL, "https://www.example.com/recieve_photos.php", viewUploadedPictures, function(error) {
        $ionicLoading.show({template: 'connection error...'});
        $ionicLoading.hide();
    }, options);
}
var viewUploadedPictures = function($) {
    $ionicLoading.show({template: 'Get uploaded pictures...'});
    $http.get('https://www.example.com/recieve_photos.php')
        .then(function (response){
            $scope.upload.result = response.data
        }).catch(function(error){
            $scope.error = error;
        });
    $ionicLoading.hide();
}

我找到了其他文档,其中展示了如何使用结果/响应进行更多调试:

    var win = function (r) {
        console.log("Code = " + r.responseCode);
        console.log("Response = " + r.response);
        console.log("Sent = " + r.bytesSent);
        $ionicLoading.hide();
    }
    var fail = function (error) {
        alert("An error has occurred: Code = " + error.code);
        console.log("upload error source " + error.source);
        console.log("upload error target " + error.target);
        $ionicLoading.hide();
    }
    var ft = new FileTransfer();
    ft.upload(fileURL, encodeURI("https://www.example.com/recieve_photos.php"), win, fail, options);

在那之后,我知道我得到了一个错误代码3,这允许我继续进行。