Meteor用CollectionsFS上傳檔案時進度條的顯示,jquery檔案上傳進度條
在Meteo開發Web中上傳檔案用CollectionsFS非常方便,上傳檔案與上傳圖片是一樣的方法,如何上傳檔案參參考:http://blog.csdn.net/casun_li/article/details/46356379,上傳檔案時顯示進度條是非常必要的,Meteor有提供進度條UI包:Meteor-cfs-ui,顯示出來非常簡單,本文參考:https://github.com/CollectionFS/Meteor-cfs-ui
具體使用很簡單:
原文地址:http://blog.csdn.net/casun_li/article/details/46801585
1.加入ui包,進入app主目錄下:
$ meteor add cfs:ui
2.html檔案中
<input type="file" id="upload_file" ><--檔案選擇控制項-->
{{#if IsUploading}} {{#with FS.GetFile "file_records" IsUploading}} {{> FS.UploadProgressBar bootstrap=true class='progress-bar-success progress-bar-striped' showPercent=true}}</p> {{/with}}{{/if}}FS.GetFile 是將With之間的Context設定成一個FS.file執行個體, file_records是儲存資料庫的集合的名稱,IsUploading是js檔案中的helpers,得到的是正在上傳的檔案在file_record集合中的_id
3. js 檔案中:上傳檔案時拿到file_id後設定:Session.set('file_id',fileObj._id);
Template.templatename.events({ 'change #upload_file': function(event, template) {////上傳檔案 FS.Utility.eachFile(event, function(file) { FileRecords.insert(file, function (err, fileObj) { if (err) { console.log('上傳檔案失敗:'+err); return; } Session.set('file_id',fileObj._id); }); }); }});
Template.templatename.helpers({ IsUploading:function(){ return Session.get("file_id"); }});至此就能完全顯示進度條了,OK。原文地址:http://blog.csdn.net/casun_li/article/details/46801585
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。