【发布时间】:2015-12-02 08:49:53
【问题描述】:
如果我们使用 CFS for meteor 在线上传大文件,并且当存储(不上传)完成时我们必须触发另一个事件,例如解压缩文件,那么我们将如何做呢? isUpload 在这种情况下不合适,因为文件尚未存储,因此无法解压缩。写在客户端做什么。
JavaScript:
var Zipper = new FS.Collection("zip", {
stores: [new FS.Store.FileSystem("zip")]
});
if (Meteor.isClient) {
Template.upload.helpers({
'data':function(){
return Zipper.find();
}
});
Template.upload.events({
'change #fileUpload': function (event,template) {
FS.Utility.eachFile(event,function(file) {
var fileObj = new FS.File(file);
var fileId;
Zipper.insert(fileObj,function(err){
});
})
}
});
}
if (Meteor.isServer) {
Meteor.methods({
"unZipFile":function(fileId, fileName){
//unzip the file using node package
}
});
}
HTML:
<head>
<title>uploadAndZip</title>
</head>
<body>
<div class="container">
<h1>Welcome to Meteor!</h1>
{{> upload}}
</div>
</body>
<template name="upload">
<input type="file" id="fileUpload">
{{#each data}}
{{#unless this.isUploaded}}
{{> FS.UploadProgressBar bootstrap=true}}
{{/unless}}
{{/each}}
<table class="table table-striped table-hover ">
<thead>
<tr>
<th>Name</th>
<th>Size</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{{#each data}}
<tr class="success">
<td>{{name}}</td>
<td>{{size}} bytes</td>
<td>{{updatedAt}}</td>
</tr>
{{/each}}
</tbody>
</table>
</template>
我尝试向This post 寻求帮助,但没有帮助。
【问题讨论】:
-
为什么不直接使用 transformWrite? github.com/CollectionFS/…
-
我用过。我正在使用的解压缩包(decompress-zip)给出错误 [错误:偏移量超出范围]
标签: javascript node.js file-upload meteor zip