Meteor 应用程序中的 JSZip 和 cfs:collection
JSZip and cfs:collection in Meteor app
所以,我正在使用 udondan:jszip、cfs:collection,
cfs:standard-包和
cfs:filesystem 个包在我的流星应用程序中。问题是我无法将我的 zip 文件存储在 FS.COllection 中。这是一些代码:
//Defining the collection
Reports = new FS.Collection('reports',{
stores: [new FS.Store.FileSystem('reports', {path: "~/public"})]
});
//Trying to add a file to the collection
var zip = new JSZip();
Reports.insert(zip);
在 运行 之后,代码出现此错误:
Error: DataMan constructor received data that it doesn't support
有没有办法让这些包相互配合?
JSZip
对象本身不是一个文件。您可以使用 generateAsync
函数从中生成一个文件。您要创建的文件类型取决于您是否希望在客户端或服务器上 运行 以及您希望如何使用该文件。两个库支持的文件类型是:(根据文档,我自己还没有测试过所有这些)
Blob
对象(仅限客户端):{ type: 'blob' }
Uint8Array
: { type: 'uint8array' }
ArrayBuffer
: { type: 'arraybuffer' }
Buffer
对象(仅限服务器):{ type: 'nodebuffer' }
因此,例如这应该有效:
zip.generateAsync({ type: 'arraybuffer' })
.then(function (content) {
Reports.insert(content);
});
所以,我正在使用 udondan:jszip、cfs:collection, cfs:standard-包和 cfs:filesystem 个包在我的流星应用程序中。问题是我无法将我的 zip 文件存储在 FS.COllection 中。这是一些代码:
//Defining the collection
Reports = new FS.Collection('reports',{
stores: [new FS.Store.FileSystem('reports', {path: "~/public"})]
});
//Trying to add a file to the collection
var zip = new JSZip();
Reports.insert(zip);
在 运行 之后,代码出现此错误:
Error: DataMan constructor received data that it doesn't support
有没有办法让这些包相互配合?
JSZip
对象本身不是一个文件。您可以使用 generateAsync
函数从中生成一个文件。您要创建的文件类型取决于您是否希望在客户端或服务器上 运行 以及您希望如何使用该文件。两个库支持的文件类型是:(根据文档,我自己还没有测试过所有这些)
Blob
对象(仅限客户端):{ type: 'blob' }
Uint8Array
:{ type: 'uint8array' }
ArrayBuffer
:{ type: 'arraybuffer' }
Buffer
对象(仅限服务器):{ type: 'nodebuffer' }
因此,例如这应该有效:
zip.generateAsync({ type: 'arraybuffer' })
.then(function (content) {
Reports.insert(content);
});