4

How to choose or pick multiple images at the same time in phonegap camera API when using Camera.DestinationType.FILE_URI. I am able to pick only one images at a time. I am able to pick multiple files(including txt,pdf..) in sdcard using this. So i want same like for images.

navigator.camera.getPicture(function(imageData) {
window.resolveLocalFileSystemURI(imageData, function(fileEntry) {
            fileEntry.file(function(fileObj) {
                    }, onFail, {
    quality : 50,
    destinationType : Camera.DestinationType.FILE_URI
});

My cordova version 3.3, Jquery Mobile 1.3.2.

Please suggest any plugins are available to do this.

Community
  • 1
  • 1
Vini
  • 967
  • 1
  • 15
  • 33

3 Answers3

2

Use this Cordova multiple image selector plugin to choose multiple image at a time. It is good plugin for choose multiple images.

Download the above plugin and copy paste the java classes. Set the required permission. Don't forget to copy the res folder just copy and paste in your res folder.

Inside assets/www create imagepicker.js copy and paste the dowloaded imagepicker.js

In your index.html set like this:

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="imagepicker.js"></script>

<script type="text/javascript">

    document.addEventListener("deviceready",onDeviceReady,false);

    function onDeviceReady(){

        window.imagePicker.getPictures(
                function(results) {
                    for (var i = 0; i < results.length; i++) {
                        alert('Image URI: ' + results[i]);

// read file type and size and file name like below(in comment)

/* window.resolveLocalFileSystemURI(results[i], function(fileEntry){
        fileEntry.file(function(fileObj) { 
            alert(fileEntry.name);
            alert(fileObj.size);
            alert(fileObj.type);
        }); 

    }, function (error) {
            alert('Error: ' + error);
        });*/
                    }
                }, function (error) {
                    alert('Error: ' + error);
                }
            );

    }
    </script>

Note: This should work only cordova 3.0 and above and android 4.0 and above

Aravin
  • 4,126
  • 1
  • 23
  • 39
1

Open CameraLauncher.java file and replace these lines

String resizePath = getTempDirectoryPath() + "/resize.jpg";
this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis());

to

String resizePath = getTempDirectoryPath() + "/resize"+System.currentTimeMillis()+".jpg";
this.callbackContext.success("file://" + resizePath);
GabrieleMartini
  • 1,665
  • 2
  • 19
  • 26
0

var x=0;
function onPhotoDataSuccess(imageURI)
{
    x++;
    // Uncomment to view the base64-encoded image data
    console.log(imageURI);
 alert(imageURI);
    // Get image handle
    //
    var y = 'smallImage'+x;
    var smallImage = document.getElementById(y);
    alert(smallImage);
 smallImage.src = "data:image/jpeg;base64," + imageURI;
    // Unhide image elements
    //
    smallImage.style.display = 'block';
  
    // Show the captured photo
    // The in-line CSS rules are used to resize the image
    //
    //var fso=new ActiveXObject("Scripting.FileSystemObject");
    //fso.CopyFile("data:image/jpeg;base64," + imageURI,"file:///storage/sdcard/DCIM/");
      
    alert(smallImage.src)
}

where x is the loop for doing the multiple image from camera as well as from photogallery

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Eshan Chattaraj
  • 368
  • 1
  • 6
  • 19