【发布时间】:2017-06-01 23:31:15
【问题描述】:
我有一个用于 Firebase 的云功能,它在存储桶写入时触发:
exports.convertToWebP = functions.storage.object().onChange(async event => {
const path = event.data.name;
const [pictureSlug, fileName] = path.split('/');
const [fileSlug, fileType] = fileName.split('.');
// Download the file
const tmpFilePath = `/tmp/${fileSlug}.${fileType}`;
const file = bucket.file(path);
await file.download({ destination: tmpFilePath });
await imagemin(
[`tmp/${fileSlug}.${fileType}`],
'/tmp',
{ use: [ imageminWebp({quality: 50})] });
const destination = `${pictureSlug}.webp`;
await bucket.upload(tmpFilePath, { destination });
我遇到的问题是,当我在存储对象上调用 .download 方法时,它会转到 /tmp/ 文件夹,但我终生无法弄清楚如何获取 @987654323 @ 抓取文件。
这可能与我构建路径的方式有关,也可能与不支持 imagemin 的 Cloud Functions 之类的其他东西有关。
我这样做的原因是因为 ImageMagick 的本地实例不支持 webp。
另外:这个文件是一个 .ts 文件,我正在使用 typescript 编译器来创建它的 js 文件。它编译为 ES5 版本。
【问题讨论】:
-
当我在等待解决这个问题时,我决定切换到
imagemin.buffer(),只使用内存缓冲区来下载、转换和重新上传图像。
标签: firebase google-cloud-functions