简体   繁体   English

离子错误(相机和文件传输插件)

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

I am developing a mobile application and I getting an error when the user try to change the picture profile, the error after do a lot of debugging is not in the camera is in the file transfer function when I try to send the image to the server, there is no error code or message, simply the application stop work, this is the code: 我正在开发一个移动应用程序,并且当用户尝试更改图片配置文件时遇到错误,当我尝试将图像发送到服务器时,经过大量调试后的错误不在相机中,这是文件传输功能中的错误,没有错误代码或消息,只是应用程序停止工作,这是代码:

$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
});

};

Thank in advice for your help 感谢您的帮助

you are not calling return appropriately on your functions that return a promise. 您没有在返回诺言的函数上适当地调用return。 From a quick review, $scope.savePicture(); 快速查看$scope.savePicture();$scope.savePicture(); should be return $scope.savePicture(); 应该return $scope.savePicture();

and $cordovaFileTransfer.upload() should also be return $cordovaFileTransfer.upload() $cordovaFileTransfer.upload()也应return $cordovaFileTransfer.upload()

I would start there and see if you start to make some progress. 我将从那里开始,看看您是否开始取得一些进展。

I had to debug the entire application including the cat log of android and I found the problem. 我不得不调试整个应用程序,包括android的cat日志,然后发现了问题。

The problem was that I am using Ionic with crosswalk and the version of FileTransfer that I was using does not support crosswalk. 问题是我将Ionic与人行横道配合使用,而我使用的FileTransfer版本不支持人行横道。

I fix this problem just installing the last version of file transfer: 我仅安装文件传输的最新版本即可解决此问题:

cordova-plugin-file-transfer 1.2.1 "File Transfer" cordova-plugin-file-transfer 1.2.1“文件传输”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM