firebase云功能:使用sharp库创建缩略图不会生成访问令牌



我使用sharp库生成缩略图,如下所示:

const filePath128       =   path.join(path.dirname(filePath), `${_128_PREFIX}${fileName}`);
const filePath512       =   path.join(path.dirname(filePath), `${_512_PREFIX}${fileName}`);
const filePath1024      =   path.join(path.dirname(filePath), `${fileName}`);
const uploadStream128   =   bucket.file(filePath128).createWriteStream({metadata});
const uploadStream512   =   bucket.file(filePath512).createWriteStream({metadata});
const uploadStream1024  =   bucket.file(filePath1024).createWriteStream({metadata});
const pipeline128       =   sharp();
pipeline128.resize(_128_MAX_WIDTH, _128_MAX_HEIGHT).pipe(uploadStream128);
const pipeline512       =   sharp();
pipeline512.resize(_512_MAX_WIDTH, _512_MAX_HEIGHT).pipe(uploadStream512);
const pipeline1024      =   sharp();
pipeline1024.resize(_1024_MAX_WIDTH, _1024_MAX_HEIGHT).pipe(uploadStream1024);
bucket.file(filePath).createReadStream().pipe(pipeline128);
bucket.file(filePath).createReadStream().pipe(pipeline512);
bucket.file(filePath).createReadStream().pipe(pipeline1024);
return new Promise((resolve, reject) => {
let finishCount     =   0;
const checkFinish = (ee: any) => {
finishCount++;
console.log('finishCount: ', finishCount, ee);
if (finishCount === 3) { resolve(); }
}
uploadStream128.on('finish', checkFinish).on('error', checkFinish);
uploadStream512.on('finish', checkFinish).on('error', checkFinish);
uploadStream1024.on('finish', checkFinish).on('error', checkFinish);
});

所有的缩略图都是在没有任何问题的情况下生成的。但默认情况下并没有为它们创建访问令牌。在Firebase控制台中,我甚至无法查看生成的图像文件。在我从控制台进行Create new access token链接后,图像就可以查看了。

如何应对这种情况有什么帮助吗?

谢谢。

这目前无法从云函数中解决。您可以从Firebase客户端应用程序(将创建令牌(以编程方式创建下载URL,但不能从后端代码创建。

相关内容

  • 没有找到相关文章

最新更新