0
votes

im newbie on ionic development i have an app that can uploading image into a serve with a certain paramater and using post method to upload it. my problem is can i uploading image using http.post angular on ionic?based on this forum

its recommended to using cordova file transfer how can i use it with my certain parameter

what i have done its like this

html

    <!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>
    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
        <link href="css/ionic.app.css" rel="stylesheet">
        -->
    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="http://code.highcharts.com/adapters/standalone-framework.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    <script src="https://rawgit.com/pablojim/highcharts-ng/master/src/highcharts-ng.js"></script>
    <!-- cordova script (this will be a 404 during development) -->
    <script src="js/ng-cordova.min.js"></script>
    <script src="cordova.js"></script>
    <!-- your app's js -->
    <script src="js/app.js"></script>
</head>

<body ng-app="starter" ng-controller="homeController">
    <ion-pane>

        <ion-nav-title>
            <span>Upload Foto</span>
        </ion-nav-title>
        <ion-content class="padding">
            <button class="button button-block button-dark" ng-click="selImages()">
      Select Images
    </button>
            <button ng-show="images.length > 0" class="button button-block button-stable" ng-click="shareAll()">
      Share All
    </button>
            <div class="list card" ng-repeat="img in images">
                <div class="item item-image">
                    <img ng-src="{{img}}">
                </div>
                <div class="item tabs tabs-secondary tabs-icon-left">

                    <a class="tab-item assertive image-option" href="#" ng-click="removeImage(img)">
                        <i class="icon ion-trash-a assertive"></i> Remove
                    </a>
                </div>
            </div>
        </ion-content>
    </ion-pane>
</body>

</html>

my controller

angular.module('starter', ['ionic','highcharts-ng','ngCordova'])

    .run(function ($ionicPlatform) {
        $ionicPlatform.ready(function () {
            // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
            // for form inputs)
            if (window.cordova && window.cordova.plugins.Keyboard) {
                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
            }
            if (window.StatusBar) {
                StatusBar.styleDefault();
            }
        });
    })
.controller('ImagePickerCtrl', function ($scope, $rootScope, $cordovaCamera,$cordovaFileTransfer) {

        $scope.images = [];

        $scope.selImages = function () {
            $scope.upload = function() {
 
    }
            window.imagePicker.getPictures(
                function (results) {
                    for (var i = 0; i < results.length; i++) {
                        console.log('Image URI: ' + results[i]);
                        $scope.images.push(results[i]);
                    }
                    if (!$scope.$$phase) {
                        $scope.$apply();
                    }
                }, function (error) {
                    console.log('Error: ' + error);
                }
            );
        };

        $scope.removeImage = function (image) {
            $scope.images = _.without($scope.images, image);
        };

        $scope.shareImage = function (image) {
            window.plugins.socialsharing.share(null, null, image);
        };

        $scope.shareAll = function () {
            var url = "fendypradana.com/alfalahkeu/Apifalah/upload_buktibayar/format/json";
            window.plugins.socialsharing.share(null, null, $scope.images);
             var options = {
            fileKey: "avatar",
            fileName: "image.png",
            chunkedMode: false,
            mimeType: "image/png"
        };
        $cordovaFileTransfer.upload(url, targetPath, options).then(function (result) {
          console.log("SUCCESS: " + JSON.stringify(result.response));
      }, function (err) {
          console.log("ERROR: " + JSON.stringify(err));
      }, function (progress) {
           
      });

        };
    }) 

i have to include 2 paramater user_id=5 and keterangan=seragam Any suggestions would really help.

1

1 Answers

0
votes

Within the options variable

Notice 'params' property within options object

You are able to pass the params within the options object.

So

var options = {
        fileKey: "avatar",
        fileName: "image.png",
        chunkedMode: false,
        mimeType: "image/png",
        params: {
             user_id: 5,
             keterangan: 'seragam'
        }
    };