我正在尝试从Firebase函数中的Google Cloud Storage Bucket中读取图像,并使用如下所示的Sharp Library提取其中的一部分
const bucket = admin.storage().bucket('XXX.appspot.com')
const filePath = '1558520481853'
const pipeline = sharp().extract({ left: 0, top: 0, width: 30, height: 30 }).toBuffer().then(
(data:any) =>
console.log("data is::::" + data)
);
bucket.file(filePath).createReadStream().pipe(pipeline);
这失败并出现错误
TypeError: dest.on is not a function
at DestroyableTransform.Readable.pipe (/srv/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:590:8)
at Object.<anonymous> (/srv/lib/index.js:49:46)
at Generator.next (<anonymous>)
at /srv/lib/index.js:7:71
at new Promise (<anonymous>)
at __awaiter (/srv/lib/index.js:3:12)
at exports.extract_text_from_bounding_box.functions.https.onRequest (/srv/lib/index.js:39:82)
at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:49:9)
at /worker/worker.js:783:7
at /worker/worker.js:766:11
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
我正在跟踪样本https://github.com/firebase/functions-samples/blob/master/image-sharp/functions/index.js,该样本正在写回到我不需要的存储桶,只需要提取图像的base64
最佳答案
错误是在“管道”方法上。
在这行上:
bucket.file(filePath).createReadStream().pipe(pipeline);
尝试这个:
bucket.file(filePath).createReadStream().pipe(pipeline());
关于javascript - 从Google存储桶读取图像并使用Sharp进行转换失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57350814/