如何使用{{uploader}}上传文件时添加百分比上传者

时间:2016-03-09 18:42:44

标签: meteor

我在代码中使用{{uploader}},每当用户上传图片时,都会显示他("上传+ fileName ...")

这是它的代码

let upload = ( options ) => {
  template = options.template;
  let file = _getFileFromInput( options.event );
  let config = options.config;

  _setPlaceholderText( `Uploading ${file.name}...` );
  _uploadFileToAmazon( file, config );
};

问题是当用户选择一个大尺寸文件时他会等待很长时间,所以最好有一个上传百分比而不是("加载...")

我正在使用meteor add edgee:slingshot包上传到Amazon S3

这是调用上传者的代码

var uploader
  if (config === '1') {
      uploader = new Slingshot.Upload( "uploadToAmazonS3Cg1" );
  } 
  if (config === '2') {
      uploader = new Slingshot.Upload( "uploadToAmazonS3Cg2" );
  }
  if (config === '3') {
      uploader = new Slingshot.Upload( "uploadToAmazonS3Cg3" );
  }
  var progress = Math.round(uploader.progress() * 100);

我尝试创建模板助手,如下所示:

Template.uploader.helpers({
    progress: function(uploader){
        var progress = Math.round(uploader.progress() * 100)
        return progress;
    }
});

然后我用{{progress}}在我的助手里面调用它,它没有工作

我怎么能做到这一点?

1 个答案:

答案 0 :(得分:0)

我使用这样的东西:

var uploader = new Slingshot.Upload("myFileUploads")
// ...get your upload started and save the uploader (in state for React or in a template variable in Blaze)
var progress = Math.round(uploader.progress() * 100)