我使用一個(gè) Cloud Function 來調(diào)整圖像大小,第二個(gè)用于將新的圖像 URL 上傳到 Cloud Firestore。但是有些東西不起作用,因?yàn)榈诙€(gè)函數(shù)永遠(yuǎn)不會(huì)運(yùn)行。我需要可以更新 url 的 uid 和 postId。如何調(diào)用第二個(gè)函數(shù)來更新 Firestore 中的 img url?代碼const { functions, tmpdir, dirname, join, sharp, fse, gcs } = require('../../admin');const runtimeOpts = { timeoutSeconds: 120, memory: '1GB',};exports.resizeImages = functions .runWith(runtimeOpts) .storage.object() .onFinalize(async (object, context) => { const bucket = gcs.bucket(object.bucket); const filePath = object.name; const fileName = filePath.split('/').pop(); const bucketDir = dirname(filePath); const workingDir = join(tmpdir(), 'resize'); const tmpFilePath = join(workingDir, 'source.png'); if (fileName.includes('@s_') || !object.contentType.includes('image')) { return false; } await fse.ensureDir(workingDir); await bucket.file(filePath).download({ destination: tmpFilePath }); // creates 3 new images with these sizes.. const sizes = [1920, 720, 100]; var newUrl = null; const uploadPromises = sizes.map(async size => { const ext = fileName.split('.').pop(); const imgName = fileName.replace(`.${ext}`, ''); const newImgName = `${imgName}@s_${size}.${ext}`; var imgPath = join(workingDir, newImgName); newUrl = imgPath; await sharp(tmpFilePath) .resize({ width: size }) .toFile(imgPath); return bucket.upload(imgPath, { destination: join(bucketDir, newImgName), }); });
如何在 Firebase Cloud 函數(shù)中調(diào)用兩個(gè)函數(shù)
慕標(biāo)琳琳
2021-09-04 14:55:02