Html collectionfs生成下载url
我正在使用meteor和collectionfs进行一个项目 我将文件上载到collectionfs,并准备了一个文件处理程序。我可以用 {{cfsFileUrl“defaultFilehandler”} Handlebar Helper显示保存图像的url,但我无法从此url下载图像 当我将其复制到浏览器中时:Html collectionfs生成下载url,html,image,meteor,Html,Image,Meteor,我正在使用meteor和collectionfs进行一个项目 我将文件上载到collectionfs,并准备了一个文件处理程序。我可以用 {{cfsFileUrl“defaultFilehandler”} Handlebar Helper显示保存图像的url,但我无法从此url下载图像 当我将其复制到浏览器中时: localhost:3000/cfs/contacts/Nj3WzrBKhqd9Mc9NP_defaultHandler.png meteor将我路由到meteor页面(就像我编写了
localhost:3000/cfs/contacts/Nj3WzrBKhqd9Mc9NP_defaultHandler.png
meteor将我路由到meteor页面(就像我编写了localhost:3000)
最终,我想实现两件事:
第一
使用html标记显示图像:
<img src=??? alt="your image" />
服务器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:
您可以使用更新后的collectionFS的0.3.3+版本公开访问或查看这些文件
<img src="{{cfsFileUrl 'default1'}}">
其中default1
是您在ContactsFS.fileHandlers
答复2:
到目前为止,collectionFS中还没有安全的解决方案,它正在制作中。按照您的建议,图像图标会显示出来,但会因以下错误而中断:“资源被解释为图像,但使用MIME类型text/html传输:”。你知道我该怎么解决这个问题吗?嗨,我试着显示图像时遇到了一个问题。它显示了一个损坏的图像图标,错误为“资源被解释为图像,但使用MIME类型text/html传输:”。你也面临同样的问题吗?
<img src="{{cfsFileUrl 'default1'}}">