【发布时间】:2018-10-07 17:30:53
【问题描述】:
我正在开发一个应用程序,管理员可以在其中上传时间表(只是一个文件),而用户可以下载该上传的文件。它现在正在使用 Meteor 中的上传功能,并将解码的文件保存到 Mongo DB。
问题是我只能上传 16mb 左右的文件。我做了一些研究,显然你可以用 GridFS 解决这个问题。我对此很陌生,文档似乎根本没有帮助。有人可以给我一个简单的例子来说明如何使用 GridFS 来解决我的问题吗?或者有没有人推荐任何其他解决方案?
这是我用于将文件上传到服务器的 UploadSchedule 方法:
uploadSchedule() {
if (this.fileListNextMonth == null) {
this.alertController.create(
{
title: "Error",
subTitle: "Cannot upload file!",
buttons: ['Ok']
}
).present();
} else {
this.fileName = this.fileList[0].name;
this.getBase64(this.fileList[0]).then(
data =>
this.scheduleProvider.uploadSchedule(data, this.fileName, true).then(observable => {
const subscription = observable.subscribe(data => {
console.log("data: " + data);
}, err => console.error(err), () => subscription.unsubscribe());
})
);
}
}
在我的 ScheduleProvider 中有一个方法 (uploadSchedule),它使用特定文件向服务器发出 post 请求。在后端,我只是对已上传的文件进行插入,因此它将作为字符串保存到数据库中。
希望有人可以帮助我。
谢谢!
【问题讨论】:
标签: file ionic-framework meteor file-upload gridfs