第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 Firebase Cloud 函數(shù)中調(diào)用兩個(gè)函數(shù)

如何在 Firebase Cloud 函數(shù)中調(diào)用兩個(gè)函數(shù)

慕標(biāo)琳琳 2021-09-04 14:55:02
我使用一個(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),            });        });
查看完整描述

1 回答

?
隔江千里

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊

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

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


查看完整回答
反對(duì) 回復(fù) 2021-09-04
  • 1 回答
  • 0 關(guān)注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)