问题描述:

I am trying to upload an image to cloudinary using ionic cordova plugin. I can successfully post my image to cloudinary, but the response i received in xcode shows [object Object]. I would like to get the details of the response.

I tried printing the result using different ways such as iterating the keys of object, and nothing is been printed. is there a way for xcode to print out ionic console.log response? My code is as follow:

angular.module('starter.controllers', [])

.controller('DashCtrl', function($scope, $cordovaCamera, $cordovaGeolocation, $cordovaFileTransfer, $q, $base64, $translate) {

//$scope.$inject = ['$cordovaCamera','$cordovaGeolocation','$cordovaFileTransfer'];

$scope.imageURI = '';

$scope.log=function(){

console.log('hello~~~');

};

$scope.takePicture = function() {

console.log('taking pictures ....');

var uploadOptions = {

params : { 'upload_preset': "MY_PRESET"}

};

var options = {

quality: 50,

destinationType: Camera.DestinationType.FILE_URI,

sourceType: Camera.PictureSourceType.CAMERA,

encodingType: Camera.EncodingType.JPEG,

};

$cordovaCamera.getPicture(options).then(function(imageData) {

$scope.imageURI = imageData;

var ft = new FileTransfer();

function win (){

console.log('upload successful');

}

function fail(){

console.log('upload fail');

}

return $cordovaFileTransfer.upload("https://api.cloudinary.com/v1_1/MY_DOMAIN/image/upload", $scope.imageURI, uploadOptions);

})

.then(function(result){

console.log('result is~~~~~~ ', result);

console.log('print the result object '); // this shows nothing

var test1=JSON.parse(decodeURIComponent(result.response);

var test2=JSON.parse(decodeURIComponent(result);

console.log('test1 is ', test1); // didn't even print!!

console.log('test2 is ', test2); // didn't even print!!

for(var property in result[0]) {

console.log(property + "=" + obj[property]); // nothing here

}

for(var property in result[1]) {

console.log(property + "=" + obj[property]);// nothing here

}

for(var property in result) {

console.log(property + "=" + obj[property]);// nothing here

}

var url = result.secure_url || '';

var urlSmall;

if(result && result.eager[0]) { // this is not working

urlSmall = result.eager[0].secure_url || '';

console.log('url ~~~~~~~~ is ', urlSmall);

chat.sendMessage(roomId,'', 'default', urlSmall, function(result){

console.log('url is ', urlSmall);

console.log('message image url successfully updated to firebase');

})

}

// Do something with the results here.

$cordovaCamera.cleanup();

}, function(err){

// Do something with the error here

console.log('something is erroring')

$cordovaCamera.cleanup();

});

};

})

相关阅读:
Top