Ngcordova fileupload相机ios错误代码1

时间:2015-04-29 08:38:17

标签: ios ngcordova

我的ios和ngcordova fileupload有问题。不知怎的,我在ios中得到错误代码1,但我不知道为什么。

这是我从相机中检索图像的地方

$scope.getPictureFromCamera = function(){
    var options = {
        quality: 50,
        destinationType: Camera.DestinationType.DATA_URL,
        sourceType: Camera.PictureSourceType.CAMERA,
        allowEdit: false,
        encodingType: Camera.EncodingType.JPEG,
        targetWidth: 1000,
        targetHeight: 1000,
        correctOrientation: true,
        popoverOptions: CameraPopoverOptions,
        saveToPhotoAlbum: true
    };

    $cordovaCamera.getPicture(options).then(function(imageURI){
        $scope.displayURL = "data:image/jpeg;base64," + imageURI;
        $scope.pictureURL = "data:image/jpeg;base64," + imageURI;
    },
    function(error){
        console.log(error);
    });
}

这是我将图像上传到我的服务器的地方

createPostWithPicture: function(post, pictureURI){

        var url = domain+'/api/v1/statuses/create';
        var filePath = pictureURI;
        var options = {
            "fileKey": "sphoto",
            "mimeType": "image/jpeg",
            "params": post
        }

        return $cordovaFileTransfer.upload(url, filePath, options);
    },

在Android中一切正常。在IOS中,我收到以下消息的错误:

FileTransferError { code = 1; source = data:image/jpeg;base64,....

我真的找不到任何解决方案。帮助太棒了!

1 个答案:

答案 0 :(得分:0)

似乎IOS希望Camera.DestinationType为FILE_URL。所以我将我的功能改为

$scope.getPictureFromCamera = function(){
    var options = {
      quality: 50,
      destinationType: Camera.DestinationType.FILE_URL,
      sourceType: Camera.PictureSourceType.CAMERA,
      allowEdit: false,
      encodingType: Camera.EncodingType.JPEG,
      targetWidth: 1000,
      targetHeight: 1000,
      correctOrientation: true,
      popoverOptions: CameraPopoverOptions,
      saveToPhotoAlbum: true
    };
    if(device.platform == "Android"){
        options.destinationType = Camera.DestinationType.DATA_URL;
    }

    $cordovaCamera.getPicture(options).then(function(imageURI){
        if(device.platform == "Android"){
            $scope.displayURL = "data:image/jpeg;base64," + imageURI;
            $scope.pictureURL = "data:image/jpeg;base64," + imageURI;
        } else if(device.platform == "iOS"){
            $scope.displayURL = imageURI;
            $scope.pictureURL = imageURI;
        }
    },
    function(error){
        console.log(error);
    });
}