在Meteor项目中,我使用CollectionFS:S3将图像保存到S3中的存储桶中。我无法看到如何将它们加载回项目中。
我尝试使用FSFile.url()方法,如下面的代码所示,但它正在返回: /cfs/files/images/e6jQ4Txgvb37GisEQ/imagename.jpg?token=XXX
我期待一个Amazon S3网址,如s3-eu-west-1.amazonaws.com/mybucket/myfolder/imagename.jpg
view.html:
{{#each images}}
URL: {{this.url}}
<img src="{{this.url}}" alt="thumbnail">
{{/each}}
view.js
images: function () {
return images.find();
}
我在CollectionFS github页面上看到的所有示例都使用了url方法,因此无法理解为什么我无法访问图像。
答案 0 :(得分:2)
这对我有用。
在客户端(模板或客户端文件夹) 确保之前定义了 store 变量,并且具有相应的值。应该与您在S3配置中定义的名称相同。例如:
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
dismissKeyboard()
}
func dismissKeyboard(){
self.view.endEditing(true)
}
//Add to viewDidLoad:
var tapGesture = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
tableView.addGestureRecognizer(tapGesture)
//Or since you wanted to dismiss when another cell is selected use:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
dismissKeyboard()
}
定义S3Url函数:
store = {
bucket: 'my bucket name',
folder: 'folder name where files are stored'
}
使用后如:
FS.File.prototype.S3Url = function(storeName) {
var self = this;
var store = self.getCollection().storesLookup[storeName];
var urlHost = 'https://s3.amazonaws.com/';
var urlPath = [store.bucket, store.folder, this.copies[storeName].key].join('/');
return urlHost + urlPath;
}
希望它有所帮助。
PS。确保store.bucket和store.folder在客户端中设置。
答案 1 :(得分:0)
这实际上是正确的。您从服务器获取一个URL,服务器将重定向到S3上的正确文件。
换句话说,服务器在概念上充当S3的代理,用于临时访问S3上的文件(因此最后是令牌)。
如果检查图像采集服务器端(流星外壳),您将看到它指向S3集合中的相对路径。
如果没有正确显示图像,则会发生其他事情,但应该使用cfs提供的网址。