collectionfs生成下载URL

时间:2013-09-16 14:14:04

标签: html image meteor

我正在使用meteor和collectionfs进行项目。

我将文件上传到collectionfs并有一个文件处理程序。我可以使用 {{cfsFileUrl“defaultFilehandler”}}

Handlebar Helper显示保存图像的网址,但我无法从此网址下载图片。

当我将其复制到我的浏览器中时:

localhost:3000/cfs/contacts/Nj3WzrBKhqd9Mc9NP_defaultHandler.png

流星将我引导到流星页面(好像我写了localhost:3000)

最终我想实现两件事:

第一

使用html标签显示图像:

<img src=??? alt="your image" />

第二 我想确保允许用户看到此图片。

拥有'download-url'对我来说不够安全。

为了达到这一点,我完成了来自collectionFS的正常教程:

客户js

ContactsFS = new CollectionFS('contacts', { autopublish: false });

Deps.autorun(function() {
    Meteor.subscribe('myContactsFiles');
});

Template.queueControl.events({
    'change .fileUploader': function (e) {
        var files = e.target.files;
        for (var i = 0, f; f = files[i]; i++) {
            ContactsFS.storeFile(f);
        }
    }
});

服务器js

ContactsFS = new CollectionFS('contacts', { autopublish: false });

ContactsFS.allow({
    insert: function(userId, file) { 
        console.log('user'+userId+"file"+JSON.stringify(file));
        console.log("WILL SAVE:"+userId && file.owner === userId );
        return userId && file.owner === userId; 
    },
    update: function(userId, files, fields, modifier) {
        return _.all(files, function (file) {
            return (userId == file.owner);
        });  //EO iterate through files
    },
    remove: function(userId, files) { return false; }
});

Meteor.publish('myContactsFiles', function() {
    if (this.userId) {
        return ContactsFS.find({ owner: this.userId }, { limit: 30 });
    }
});


ContactsFS.fileHandlers({
  default1: function(options) { // Options contains blob and fileRecord — same is expected in return if should be saved on filesytem, can be modified
    return { blob: options.blob, fileRecord: options.fileRecord }; // if no blob then save result in fileHandle (added createdAt)
  }});

1 个答案:

答案 0 :(得分:2)

答案1:

您可以使用更新的0.3.3+版本的collectionFS公开使这些文件可访问,或查看它们。

<img src="{{cfsFileUrl 'default1'}}">

其中default1是您在ContactsFS.fileHandlers

中定义的处理函数的名称

答案2:

截至目前,还没有安全的解决方案构建到collectionFS中,它正在制作中。

相关问题