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

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

Firebase云功能存儲可先觸發第一個縮略圖URL,然后再觸發與第一個相同的縮略圖URL

Firebase云功能存儲可先觸發第一個縮略圖URL,然后再觸發與第一個相同的縮略圖URL

千萬里不及你 2021-04-12 13:14:40
我正在嘗試將圖像上傳到Firebase,然后生成2個縮略圖。我能夠做到這一點沒有問題。我目前的障礙是,當我將URL寫入實時數據庫時,我總是得到與初始上傳相同的URL。例如:第一次上傳時,我上傳的圖像帶有該圖像的兩個適當的縮略圖第2次上傳我得到的上傳的圖像帶有前兩個縮略圖(第一個圖像)第三次上傳時,我得到的上傳的圖片帶有第一個圖片的縮略圖... ...這將繼續復制第一個上傳的網址在我的存儲中,正在生成正確的縮略圖,但是URL始終是第一次上傳嗎?我不知道這是否是getSignedUrl()的問題,真的不知道這里發生了什么。這是我的云函數: export const generateThumbs = functions.storage    .object()    .onFinalize(async object => {    const bucket = gcs.bucket(object.bucket); // The Storage object.    // console.log(object);    console.log(object.name);    const filePath = object.name; // File path in the bucket.    const fileName = filePath.split('/').pop();    const bucketDir = dirname(filePath);    const workingDir = join(tmpdir(), 'thumbs');    const tmpFilePath = join(workingDir, 'source.png');    if (fileName.includes('thumb@') || !object.contentType.includes('image')) {      console.log('exiting function');      return false;    }    // 1. ensure thumbnail dir exists    await fs.ensureDir(workingDir);    // 2. Download Sounrce fileName    await bucket.file(filePath).download({      destination: tmpFilePath    });    //3. resize the images and define an array of upload promises    const sizes = [64, 256];    const uploadPromises = sizes.map(async size => {      const thumbName = `thumb@${size}_${fileName}`;      const thumbPath = join(workingDir, thumbName);      //Resize source image      await sharp(tmpFilePath)      .resize(size, size)      .toFile(thumbPath);      //upload to gcs      return bucket.upload(thumbPath, {        destination: join(bucketDir, thumbName),        metadata: {         contentType: 'image/jpeg'       }      })
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 159 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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