Get a picture, upload it to the server

Got it working. Thanks a lot @bengtler. The ngCordova docs do not include the ftOptions section. Lesson for me to always read the cordova docs first. Really appreciate the help.

Updated, working example for anyone interested. @bengtler are you using the same options and structure for Android + iOS?

var options = {
        quality: 50,
        destinationType: Camera.DestinationType.FILE_URL,
        sourceType: imageSource,
        allowEdit: true,
        encodingType: 0,
        targetWidth: 100,
        targetHeight: 100,
        popoverOptions: CameraPopoverOptions,
        saveToPhotoAlbum: false
        // chunkedMode: false
    };

    console.log(options);

    $cordovaCamera.getPicture(options).then(function(imageData) {
      console.log(imageData);

        var server = apiURL + '/uploads.json?' + apiKey + "&api_username=" + $rootScope.user.user.username;

        var trustAllHosts = true;

        var ftOptions = new FileUploadOptions();
        ftOptions.fileKey = 'file';
        ftOptions.fileName = imageData.substr(imageData.lastIndexOf('/') + 1);
        ftOptions.mimeType = 'image/jpeg';
        ftOptions.httpMethod = 'POST';

            $cordovaFileTransfer.upload(encodeURI(server), imageData, ftOptions, trustAllHosts)
              .then(function(result) {
              console.log('success: ' + angular.toJson(result));
              },
              function(err) {
              // Error
                console.log('error: ' + err);
              },
              function (progress) {
              // constant progress updates
            });

        // $scope.hideCameraActions();
    }, function(err) {
        // error
        console.log(err);
    });
}
2 Likes