我正在尝试使用gridfs
下载从MongoDB上传的文件。下载适用于小文件,但不适用于大于1MB
的文件,没有错误消息没有发生。有没有解决文件大小问题的方法?
事件:
Template.form.events({
"click #chunk": function() {
let doc = Images.findOne({_id:"TK8mmSg9CvjxwSxE5"});
let chunk = filenamechunks.find({files_id:new Meteor.Collection.ObjectID(doc.copies.images.key)}).fetch();
if (chunk.length > 0) {
let chunksize = 0xffff;
let len = chunk[0].data.length;
let strings = [];
for (var y = 0; y < chunk.length; y++) {
for (var i = 0; i * chunksize < len; i++){
strings.push(String.fromCharCode.apply(null, chunk[y].data.subarray(i * chunksize, (i + 1) * chunksize)));
};
};
let content = btoa(strings.join(''));
let link = window.document.createElement("a");
link.setAttribute("href", "data:"+doc.copies.type+";base64," + content);
link.setAttribute("download", "test."+doc.copies.name.split(".")[1]);
link.click();
};
}
});
HTML:
<template name="form">
<button id="chunk">click</button>
</template>
发布
Meteor.publish("chunks", function(id){
return filenamechunks.find({files_id:new Meteor.Collection.ObjectID(id)});
});
订阅:
Template.form.onCreated(function() {
this.subscribe("chunks","56fbaa2c850d6b341a0c3344");
});
包装: