亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Firebase Cloud 函數中調用兩個函數

如何在 Firebase Cloud 函數中調用兩個函數

慕標琳琳 2021-09-04 14:55:02
我使用一個 Cloud Function 來調整圖像大小,第二個用于將新的圖像 URL 上傳到 Cloud Firestore。但是有些東西不起作用,因為第二個函數永遠不會運行。我需要可以更新 url 的 uid 和 postId。如何調用第二個函數來更新 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),            });        });
查看完整描述

1 回答

?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

您的第二個功能似乎嵌入在第一個功能中。這行不通。所有函數定義都必須在頂層,以便 Firebase CLI 可以檢測到它們并單獨部署。

如果您實際上不需要兩個單獨的函數定義,只需在一個函數中執行所有工作,不要嘗試使用函數 SDK 來完成任何工作。Functions SDK 僅用于定義用于部署的函數。


查看完整回答
反對 回復 2021-09-04
  • 1 回答
  • 0 關注
  • 190 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號