2

コードバ上で実行されるイオンでハイブリッドアプリを構築しています。$cordovaCamera プラグインを使用して、電話のギャラリーから選択するか、カメラを使用して写真を撮ることにより、電話から画像をキャプチャします。

次に、 Restangularを使用してその画像をサーバーに送信し、そのアクションが終了したら、画面にステータス メッセージを表示したいと考えています。

私の問題:上記のすべてがAndroidで完全に機能します。iOS では、画像がギャラリーから選択された場合にのみ機能しますが、画像が電話から直接キャプチャされた場合には機能しません。その場合、画像はサーバーに正しく転送され、リクエストは本来あるべき 201 Created を返しますが、then()コールバック関数は入力されません。

誰かがこの動作を説明できるなら、それは素晴らしいことです...私の次善の策は、iPhoneで画像をキャプチャし、ギャラリーに保存してから、最後に保存された画像を取得しようとすることですが、私には理解できませんでした方法はまだありませんが、これを機能させたいだけです。

更新: Restangular 部分に絞り込みました。Restangular アップロード関数を呼び出す代わりに $http を使用すると、コールバックが期待どおりにトリガーされ、すべて問題ありません...それが私がやろうとしていることです。しかし、誰かが私に問題が何であったかを教えてくれれば、私は感謝します.

関連コード:

/** cameraService functions **/

//when the user chooses to snap a picture from the camera 
takePicture: function(){
            var options = {
                quality: 50,
                destinationType: Camera.DestinationType.DATA_URL,
                sourceType: Camera.PictureSourceType.CAMERA,
                encodingType: Camera.EncodingType.JPEG,
                popoverOptions: CameraPopoverOptions
            };

            return $cordovaCamera.getPicture(options).then(
                function(imageData) {
                    return imageData;
            },
                function(err) {
                    console.log("error", err);
            });
        },

        //when the user chooses to select image from the gallery
        choosePicture: function(){
            var options = {
                destinationType: Camera.DestinationType.DATA_URL,
                sourceType: Camera.PictureSourceType.PHOTOLIBRARY
            };

            return $cordovaCamera.getPicture(options).then(
                function(imageData) {
                    return imageData;
                },
                function(err) {
                    console.log("error", err);
                });
        },
        uploadPicture: function(imageSource, caption, is_logo){
            if (typeof is_logo == 'undefined') is_logo = false;
            var upload_object = {
                caption: caption,
                source: imageSource,
                is_logo: is_logo
            };
//apiService is my wrapper for Restangular
            return apiService.uploadFile(loadingService.getClientUrl('images'), upload_object);

        },


/**apiService uploadFile - apparently the problem is here ***/
uploadFile: function(baseElem, object, route, path){
    var headers = apiFunctions.setHeaders({'Content-Type': undefined});

//this DOES NOT WORK (on iPhone with image from camera) - request completes but callback not triggered 
    return Restangular.all(baseElem).customPOST(object, path, route, headers);
//this works fine:
return $http.post('https://api.mysite.dev/v1/clients/'+localStorageService.getValue('client_id')+'/images', JSON.stringify(object), {headers:headers}
                );

            },


/** controller functions **/

        $scope.takePicture = function () {
            cameraService.takePicture().then(function (imageData) {
                $scope.data.imageSource = imageData;
            });
        };
        $scope.choosePicture = function () {
            cameraService.choosePicture().then(function (imageData) {
                $scope.data.imageSource = imageData;
            });
        };
        $scope.uploadPicture = function () {
            cameraService.uploadPicture($scope.data.imageSource, $scope.data.caption)
                .then(function (response) { //this is never entered if image is captured from camera on iPhone 
                    $ionicScrollDelegate.scrollTop();
                    $scope.data.caption = '';
                    $scope.data.imageSource = '';
                    if (response.data.response.is_success.data_value == true) {
                        $scope.messages.success.push("Photo uploaded successfully");
                    } else {
                        $scope.messages.failure.push("Error uploading photo.");
                    }
                });
        }
4

0 に答える 0