【发布时间】:2015-10-06 19:21:21
【问题描述】:
我有一组图像存储在我的/private 子目录中,我正在尝试在服务器方法中检索数据并将数据发送回客户端以进行显示。
我该怎么做?
我在/private/photos 中有一个名为test.png 的图像。这是我尝试过的。
/client/test.js
Template.test.onRendered(function () {
Meteor.call('returnPhoto', 'photos/test.png', function (e, data) {
console.log(data);
console.log(window.btoa(data));
$('#imgContainerImg').attr('src', 'data:image/png;base64,' + window.btoa(data));
});
})
/server/methods.js
returnPhoto: function (assetPath) {
return Assets.getText(assetPath);
return Assets.getBinary(assetPath);
}
我尝试了Assets.getText 和Assets.getBinary,第一个给了我一些二进制乱码,第二个给了我一个数字数组。无论如何使用btoa 函数都不起作用。
我查看了CollectionFS 包,但我不需要上传图片并将它们全部存储在一个集合中。我希望将图像放入该目录后立即可用,而无需致电myFSCollection.insert。
【问题讨论】:
标签: javascript image meteor binary