使用Phonegap文件API获取所有文件名 [英] Get all filenames using Phonegap file API
问题描述
我正在使用Phonegap文件上传将SVG文件上传到我的服务器。它工作正常。但我需要从iPad的绝对路径中取出所有的SVG文件,并将它们发送到我的服务器。我不知道如何获取所有的.svg文件使用Phonegap的文件API,以便我可以发送到服务器循环通过文件名。
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.
我的文件上传代码是:
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);
}
推荐答案
a href =http://docs.phonegap.com/en/1.8.1/cordova_file_file.md.html#DirectoryReader> DirectoryReader ,并循环遍历查找.svg文件的所有条目。
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.
这篇关于使用Phonegap文件API获取所有文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!