gpt4 book ai didi

javascript - FS.Store.GridFS 由变换创建 : false

转载 作者:太空宇宙 更新时间:2023-11-04 02:16:35 24 4
gpt4 key购买 nike

我尝试保存使用 Meteor-CollectionFS 的图像文件

但是失败了。图像模型

/**
* Create collections Images
* @type {FS.Collection}
*/
Images = new FS.Collection("images", {
stores: [
/**
* Use GridFS stores
*/
new FS.Store.GridFS("original"),
new FS.Store.GridFS("thumbnail", {
transformWrite: function(fileObj, readStream, writeStream) {
gm(readStream, fileObj.name()).resize('32', '32', '!').stream().pipe(writeStream);
}
})
],
filter: {
allow: {
contentTypes: ['image/*']
}
}
});

接下来将图像保存在 Controller 中

this.saveCroppedImage = () => {
if (this.myCroppedImage !== '') {
Images.insert(this.myCroppedImage, (err, fileObj) => {
if (!this.newParty.images) {
this.newParty.images = [];
}

console.log(fileObj);

this.newParty.images.push(fileObj);
this.cropImgSrc = undefined;
this.myCroppedImage = '';
});
}
};

fileObj 没有 url() 方法。如果尝试获取图像链接,则会捕获 503 错误。但如果将链接放入浏览器中 - 图像存在

最佳答案

如果您使用 angular-meteor 并且 image._id 存在于集合中 - 不订阅集合图像 - 在客户端上使用此功能

var getImageLink = function (imageId, store = "thumbnail") {
var authToken = FS.Utility.btoa(JSON.stringify({
authToken: Accounts._storedLoginToken() || '',
}));
return "/cfs/files/images/"+imageId+"?token="+authToken+"&store="+store;
}

关于javascript - FS.Store.GridFS 由变换创建 : false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35456944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com