【问题标题】:ionic FileTransfer gives no result/errors/feedback, and then does do the success functionionic FileTransfer 没有给出结果/错误/反馈,然后执行成功功能
【发布时间】:2016-11-07 20:16:23
【问题描述】:

我有一个 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();
}

【问题讨论】:

    标签: javascript android ionic-framework file-transfer


    【解决方案1】:

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

        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,这让我可以继续前进。

    【讨论】:

      猜你喜欢
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多