Cordova Image Picker, To upload Multiple images once

2k views Asked by At

I have the following codes and it successfully select many images as i want.

angular.module('appControllers', [])

.controller('HomeCtrl', ['$scope', '$rootScope', '$cordovaCamera', function($scope, $rootScope, $cordovaCamera) {

    $scope.ready = false;
    $scope.images = [];

    $rootScope.$watch('appReady.status', function() {
        console.log('watch fired '+$rootScope.appReady.status);
        if($rootScope.appReady.status) $scope.ready = true;
    });

    $scope.selImages = 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);
            }
        );
    };
}])

Reference:- http://www.raymondcamden.com/2015/03/12/selecting-multiple-images-in-a-phonegapcordova-app

My question how do i upload to server using PHP as backend Programming and Angular Js as FrontSide?

Thanks in Advance!

1

There are 1 answers

0
Daniel Kim On

Use fileTransfer plugin here in your success callback.

var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
options.mimeType = "image/jpg"; //or for any other extention, use fileURL.split('.').pop();

var ft = new FileTransfer();
ft.upload(fileURL, encodeURI("http://some.server.com/upload.php"), success_callback, error_callback, options);

and about how to handle files sent to your server, check out here.

I looked over the fileTranfer plugin's documentation and saw that it has the 'chunked' mode as default. I don't know for sure there is a ready-out-of-box php library for this specific plugin(let me know if there is, because I'm planning to do what your are doing now in soon time) but this chunked mode approach has been well documented and widely used, so you should be able to find a solution.

hope other see this thread and give you real help.