mma*_*han 2 javascript ipad cordova
我正在使用Phonegap文件上传将SVG文件上传到我的服务器.它工作正常.但是我需要从iPad的绝对路径中获取所有SVG文件并将它们发送到我的服务器.我不知道如何使用Phonegap的文件API获取所有.svg文件,以便我可以通过文件名发送到服务器.请告诉我怎么做.
我的文件上传代码是:
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);
}
Run Code Online (Sandbox Code Playgroud)
您需要从根文件系统创建一个DirectoryReader,并遍历查找.svg文件的所有条目.
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可能需要对此代码进行一些小的编辑,但它应该让您开始.