我已经按照collectionFS指南和其他几个stackoverflow问题[这里] [1],但我仍然在显示图像时遇到错误.显示损坏的图像图标,控制台打印"资源解释为图像,但使用MIME类型text/html传输:".知道我能做些什么来解决这个问题?
我的代码如下:
HTML
<template name="fileList">
{{#each images}}
{{name}}
<img src="{{cfsFileUrl 'default1'}}">
<br />
{{else}}
No Files uploaded
{{/each}}
</template>
Run Code Online (Sandbox Code Playgroud)
客户端JS
Template.fileList.helpers({
'images': function(){
return ImagesFS.find({}, {sort: {uploadDate:-1}});
}
});
Run Code Online (Sandbox Code Playgroud)
服务器JS
if(Meteor.isServer){
ImagesFS.fileHandlers({
default1: function(options) { // Options contains blob and fileRecord — same is expected in return if should be saved on filesytem, can be modified
console.log('I am handling default1: ' + options.fileRecord.filename);
console.log(options.destination());
return { blob: options.blob, fileRecord: options.fileRecord }; // if no blob then save result in fileHandle (added createdAt)
}
});
}
Run Code Online (Sandbox Code Playgroud)
通过以下方式手动添加cfs-public-folder包,我得到了这个工作:
meteor add cfs-public-folder
Run Code Online (Sandbox Code Playgroud)
现在文件显示在浏览器中,并且URL显示在
http://localhost:3000/cfs/<collectionFS name>/<imageId_fileHandler.ext>
Run Code Online (Sandbox Code Playgroud)
作品.
| 归档时间: |
|
| 查看次数: |
891 次 |
| 最近记录: |