簡體   English   中英

離子錯誤(相機和文件傳輸插件)

[英]Ionic error (Camera and File transfer plugin)

我正在開發一個移動應用程序,並且當用戶嘗試更改圖片配置文件時遇到錯誤,當我嘗試將圖像發送到服務器時,經過大量調試后的錯誤不在相機中,這是文件傳輸功能中的錯誤,沒有錯誤代碼或消息,只是應用程序停止工作,這是代碼:

$scope.addImage = function (option) {
var options = {
  quality: 75,
  targetWidth: 300,
  destinationType: Camera.DestinationType.DATA_URL,
  targetHeight: 300,
  saveToPhotoAlbum: false,
  correctOrientation: true
};

if (option == 1) {
  options.sourceType = Camera.PictureSourceType.CAMERA;
} else {
  options.sourceType = Camera.PictureSourceType.PHOTOLIBRARY;
}

$cordovaCamera.getPicture(options).then(function (imageData) {
  console.log("IMAGE DATA");
  console.log(imageData);
  //alert("SUCCESS");
  $scope.user.image = "data:image/jpeg;base64," + imageData;
  console.log(JSON.stringify($scope.user));
  $scope.savePicture();
}, function (err) {
  alert("ERRROR");
  alert(JSON.stringify(err));
  // An error occured. Show a message to the user
});
};



$scope.savePicture = function () {
  var options = {
    fileKey: "avatar",
    fileName: "image.jpg",
    chunkedMode: false,
    mimeType: "image/jpeg",
    headers: {
      Authorization: "Bearer " + $auth.getToken()
    }
  };

  $cordovaFileTransfer.upload(api.getApi()+"user/updatephoto", $scope.user.image, options).then(function (result) {
    console.log("SUCCESS: " + JSON.stringify(result.response));
}, function (err) {
    console.log("ERROR: " + JSON.stringify(err));
    alert("ERROR: " + JSON.stringify(err));
}, function (progress) {
    // constant progress updates
});

};

感謝您的幫助

您沒有在返回諾言的函數上適當地調用return。 快速查看$scope.savePicture();$scope.savePicture(); 應該return $scope.savePicture();

$cordovaFileTransfer.upload()也應return $cordovaFileTransfer.upload()

我將從那里開始,看看您是否開始取得一些進展。

我不得不調試整個應用程序,包括android的cat日志,然后發現了問題。

問題是我將Ionic與人行橫道配合使用,而我使用的FileTransfer版本不支持人行橫道。

我僅安裝文件傳輸的最新版本即可解決此問題:

cordova-plugin-file-transfer 1.2.1“文件傳輸”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM