多个用户使用相同功能时的 Firebase 云功能截止日期错误

问题描述

每当用户必须在存储中发布图像时,我都不会直接使用 firebase 存储功能来执行此操作,而是使用 onCall 云功能通过向其传递 base64 图像、修改它(5 次)并将其发布到存储。

功能如下:

exports.uploadImage = functions.https.onCall(async (data,context) => {
    

   var bucket = admin.storage().bucket(); 

   // Convert the base64 string back to an image 
   var base64EncodedImageString = data.image,mimeType = 'image/jpeg',fileName = 'testName',imageBuffer = Buffer.from(base64EncodedImageString,'base64');

   if (!fs.existsSync(os.tmpdir()+"/myfolder")){
      fs.mkdirsync(os.tmpdir()+"/myfolder");
  }

   const tempFilePath = path.join(os.tmpdir(),"myfolder",fileName+".jpg");


   fs.writeFileSync(tempFilePath,base64EncodedImageString,'base64',function(err){
      functions.logger.log("file scritto in"+tempFilePath);
   })
  
   await bucket.upload(tempFilePath,{
      destination: 'test/'+fileName,Metadata: { contentType: mimeType,Metadata: {
            firebaseStorageDownloadTokens: uuid()
         } 
       },});


   const tempFilePath_25 = path.join(os.tmpdir(),fileName+"_25.jpg");
   spawnSync('convert',[tempFilePath,'-scale','10%','1000%>',tempFilePath_25]);
   await bucket.upload(tempFilePath_25,{
      destination: 'test/'+fileName+"_25.jpg",});
    fs.unlinkSync(tempFilePath_25);
      
   const tempFilePath_50 = path.join(os.tmpdir(),fileName+"_50.jpg");
   spawnSync('convert','5%','2000%>',tempFilePath_50]);
   await bucket.upload(tempFilePath_50,{
      destination: 'test/'+fileName+"_50.jpg",});
    fs.unlinkSync(tempFilePath_50);

   const tempFilePath_75 = path.join(os.tmpdir(),fileName+"_75.jpg");
   spawnSync('convert','3%','3333%>',tempFilePath_75]);
   await bucket.upload(tempFilePath_75,{
      destination: 'test/'+fileName+"_75.jpg",});
    fs.unlinkSync(tempFilePath_75);

   const tempFilePath_100 = path.join(os.tmpdir(),fileName+"_100.jpg");
   spawnSync('convert','1%','10000%>',tempFilePath_100]);
   await bucket.upload(tempFilePath_100,{
      destination: 'test/'+fileName+"_100.jpg",});
    fs.unlinkSync(tempFilePath_100);


});

我尝试每 2 秒用 for 循环进行一次模拟,但我收到 60% 请求的截止日期错误。当我发布应用程序时,会有很多用户(希望如此)可以同时调用相同的函数来发布照片。我怎么解决这个问题?提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)