2

I am using Phonegap file upload to upload SVG files to my server. It's working fine. But I need to take all SVG files from the iPad's absolute path and send them to my server. I don't know how to get all .svg files using Phonegap's file API, so that I can send to the server looping through file names. Please tell me how to do this.

My code for file upload is:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
  window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
  fileSystem.root.getFile("image5_2.jpg.svg", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
  var localpath=fileEntry.fullPath;
  uploadPhoto(localpath);
}
function uploadPhoto(imageURI) {
  var options = new FileUploadOptions();
  var ft = new FileTransfer();
  ft.upload(imageURI, "http://192.168.1.54:8080/POC/fileUploader", win, fail, options);
}
dda
  • 6,030
  • 2
  • 25
  • 34
mmathan
  • 273
  • 1
  • 5
  • 13

1 Answers1

7

You need to create a DirectoryReader from the root FileSystem and loop through all the entries looking for .svg files.

function gotFS(fileSystem) {
    var reader = fileSystem.root.createReader();
    reader.readEntries(gotList, fail);    
}

function gotList(entries) {
    var i;
    for (i=0; i<entries.length; i++) {
        if (entries[i].name.indexOf(".svg") != -1) {
            uploadPhoto(entries[i].fullPath);
        }
    }
}

You may have to make some minor edits to this code but it should get you started.

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • thanks simon and i checked ur blog regarding listing all files in directory. its very helpful.. – mmathan Jun 18 '12 at 04:37