2016-10-15 2 views
0

Ich bin ein Neuling auf ionische Entwicklung Ich habe eine App, die Bild in einen Aufschlag mit einem bestimmten Parameter hochladen und Post-Methode, um es hochladen kann. mein Problem ist, kann ich Bild hochladen mit http.post Winkel ionischer? basierend auf diesem ForumBild Upload zu API-Service mit http POST ionic angular.js

seine empfohlen, mit Cordova Dateiübertragung Wie kann ich es mit meinem bestimmten Parameter verwenden

, was ich seine wie dieses würde

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 umfassen müssen 2 Paramater user_id = 5 und keterangan = seragam

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> 

mein Controller wirklich Irgendwelche Vorschläge gemacht haben helfen.

Antwort

0

Innerhalb der Optionen Variable

Notice 'params' property within options object

Sie sind in der Lage, die params innerhalb der Optionen Objekt zu übergeben.

So

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