Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase函数上的Firebase仿真器存储_Firebase_Google Cloud Functions_Google Cloud Storage_Firebase Storage - Fatal编程技术网

Firebase函数上的Firebase仿真器存储

Firebase函数上的Firebase仿真器存储,firebase,google-cloud-functions,google-cloud-storage,firebase-storage,Firebase,Google Cloud Functions,Google Cloud Storage,Firebase Storage,昨天,google发布了新的firebase存储模拟器,所以我在firebase函数模拟器中通过http函数触发的firebase函数中进行了尝试 我将文件txt放在他们的gs://defaultbucket/模板文件夹中,然后运行此代码 const functions = require("firebase-functions"); exports.document= functions.https.onRequest( async (req,res) => {

昨天,google发布了新的firebase存储模拟器,所以我在firebase函数模拟器中通过http函数触发的firebase函数中进行了尝试

我将文件txt放在他们的gs://defaultbucket/模板文件夹中,然后运行此代码

const functions = require("firebase-functions");


exports.document= functions.https.onRequest( async (req,res) => {

const cors =  require('cors');
const admin = require('firebase-admin');

if (!admin.apps.length){
    try{
        console.log("firebase admin initialize")
        admin.initializeApp();
    }
    catch (e){
        console.log(e.message)
    }
}
//declare libraries

const path = require('path');
const os = require('os');
const fs = require('fs');

const corsHandler = cors({
    origin: true
})
return corsHandler(req,res, async ()=>{
    const data = req.body;
    const filename = data.filename;
    
    
    

   

    
    

    const bucket = admin.storage().bucket('default-bucket');

    const tempFilePath = path.join(os.tmpdir(),filename);
    const filePath = "template/" + filename
    
    console.log('download file from bucket')
   
    await bucket.file(filePath).download({destination:     tempFilePath});

    console.log('file downloaded')
    
  })
 })
发现的错误是这样写的: (节点:2602)未处理的PromisejectionWarning:错误:下载的数据与服务器上的数据不匹配。为了确保内容相同,您应该再次下载该文件

有人尝试过emulator存储并成功了吗?请帮忙


谢谢

同样发布在:您共享的代码似乎没有实现云功能。在异步函数外部使用wait。这是全部代码吗?不只是剪断,可以编辑以显示完整的firebase功能