Meteor用CollectionsFS上傳檔案時進度條的顯示,jquery檔案上傳進度條

來源:互聯網
上載者:User

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 


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.