最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get all filenames using Phonegap file API - Stack Overflow

programmeradmin5浏览0评论

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);
}

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);
}
Share Improve this question edited Jun 17, 2012 at 4:14 dda 6,2132 gold badges27 silver badges35 bronze badges asked Jun 16, 2012 at 11:10 mmathanmmathan 2731 gold badge5 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论