【发布时间】:2015-01-11 00:23:28
【问题描述】:
我有一些使用 meteorJS 开发 Web 应用程序的经验,但我才刚刚开始使用 Cordova/混合应用程序开发。如何在流星应用程序中访问 android 文件系统? 例如,如果我想在流星模板中向用户显示设备上的图片或媒体文件列表,我该如何获取这些文件或这些文件的路径?
【问题讨论】:
-
这回答了如何读取文件的问题。但我想知道如何将文件拉入流星?
我有一些使用 meteorJS 开发 Web 应用程序的经验,但我才刚刚开始使用 Cordova/混合应用程序开发。如何在流星应用程序中访问 android 文件系统? 例如,如果我想在流星模板中向用户显示设备上的图片或媒体文件列表,我该如何获取这些文件或这些文件的路径?
【问题讨论】:
从List files inside www folder in PhoneGap 修改为流星的答案:
if (Meteor.isCordova) {
Meteor.startup(function () {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getDirectory("Download", {
create: true
}, function(directory) {
var directoryReader = directory.createReader();
directoryReader.readEntries(function(entries) {
var i;
for (i=0; i<entries.length; i++) {
console.log(entries[i].name);
var fileName = (entries[i].name);
var fullPath = (entries[i].fullPath);
var fileItem = {
name: fileName,
path: fullPath
};
Files.insert(fileItem); // inserts files into a mongo collection named "Files"
}
}, function (error) {
alert(error.code);
});
} );
}, function(error) {
alert("can't even get the file system: " + error.code);
});
});
}
【讨论】: