【问题标题】:cfs display uploaded files in client sidecfs 在客户端显示上传的文件
【发布时间】:2015-11-25 18:40:53
【问题描述】:

我的代码: 服务器/app.js

var imageLargeStore = new FS.Store.S3("imagesLarge", {
  accessKeyId: "xxxx", 
  secretAccessKey: "xxx", 
  bucket: "profile-thumbs", 
  transformWrite: function(fileObj, readStream, writeStream) {
    gm(readStream, fileObj.name()).resize('250', '250').stream().pipe(writeStream)
  }
});
var imageSmallStore = new FS.Store.S3("imagesSmall", {
  accessKeyId: "xxxx", 
  secretAccessKey: "xxx",
  bucket: "profile-thumbs",
  transformWrite: function(fileObj, readStream, writeStream) {
    gm(readStream, fileObj.name()).resize('80', '80').stream().pipe(writeStream)
  }
});


thumbs = new FS.Collection("images", {
  stores: [imageLargeStore,imageSmallStore]
});
Meteor.publish("images", function() {
  return thumbs.find();
});
thumbs.allow({
  insert: function (userId, doc) {
    return true;
  },
  update: function (userId, doc, fields, modifier) {
    return true;
  },
  remove: function (userId, doc) {
    return true;
  },
  download:function(){
    return true;
  }
});

client/app.js

var imageLargeStore = new FS.Store.S3("imagesLarge");
var imageSmallStore = new FS.Store.S3("imagesSmall");
thumbs = new FS.Collection("images", {
  stores: [imageLargeStore,imageSmallStore],
  filter: {
    allow: {
      contentTypes: ['image/*']
    }
  }
})

上传工作正常,我可以在 aws 中看到图像

thumbs.insert(res,function(err,fileobj){
      console.log(fileobj);
    })

我在客户端发布并订阅了所有集合

我尝试显示图像,但它们没有显示

{{#each images}}
    <div>
       <a href="{{this.url}}" target="_blank"><img src="{{this.url store='imageSmallStore' uploading='/amazon.png' storing='/angjs.jpg'}}" alt="" class="thumbnail" /></a>
                </div>

 {{/each}}

images:function(){
  return thumbs.find({});
}

但是图像没有显示,而不是存储图像(angjs.jpg)正在显示。

当我检查元素时,我可以看到类似的 url

但是图片没有显示,我的代码有什么问题?

当我尝试在 aws 控制台中打开 Image 时遇到此错误

【问题讨论】:

  • 如果你把这个你得到什么? &lt;a href="{{this.url}}" target="_blank"&gt;&lt;img src="{{this.url store='imageSmallStore' }}" alt="" class="thumbnail" /&gt;&lt;/a&gt;
  • @Ethaan,不,那不行
  • 您找到解决方案了吗?我也遇到了类似的事情

标签: meteor


【解决方案1】:

我认为发生的情况是您正在为集合定义允许规则,但仅在服务器上。客户端还需要访问集合的download 属性才能访问文件的数据(不是实际图像)

官方文档的那种解释https://github.com/CollectionFS/Meteor-CollectionFS#security

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-20
    • 2017-09-07
    • 2012-02-03
    • 2023-04-09
    • 2021-06-30
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    相关资源
    最近更新 更多