Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.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
Node.js将图像上载到firebase存储_Node.js_Firebase_Google Cloud Platform_Google Cloud Functions - Fatal编程技术网

Node.js将图像上载到firebase存储

Node.js将图像上载到firebase存储,node.js,firebase,google-cloud-platform,google-cloud-functions,Node.js,Firebase,Google Cloud Platform,Google Cloud Functions,我正在尝试在firebase cloud函数中上载文件(图像)。在阅读了许多帖子后,我发现我唯一能做到这一点的方法就是使用谷歌云平台(GCP)API,下面是我的代码: const storage = require('@google-cloud/storage')(); var bucket = storage.bucket('myBucketName'); var buffer = bufferRepresentMyImage; // what next? 我从GCP的API中找到了以下代码

我正在尝试在firebase cloud函数中上载
文件(图像)
。在阅读了许多帖子后,我发现我唯一能做到这一点的方法就是使用
谷歌云平台(GCP)API
,下面是我的代码:

const storage = require('@google-cloud/storage')();
var bucket = storage.bucket('myBucketName');
var buffer = bufferRepresentMyImage;
// what next?
我从GCP的API中找到了以下代码:

bucket.upload(filename, (err, file) => {
    // code goes here
});

然而,它似乎不起作用,因为它从不要求文件的数据,相反,
回调函数
返回一个
文件
。有谁能告诉我如何使用
bucket
上传
图像

选项参数中包含远程目标文件名<代码>文件名在您的示例(以及这个答案)中是本地文件名路径

let options = {
        destination: fileNameOnDestinationBucket,
        metadata: {                   // (optional)
            metadata: yourCustomMetadata,
            contentType: 'image/jpeg' // (example)
        }
    };

// with Promise:
bucket.upload(filename, options).then((response)=>{
    ...
});

// with callback:
bucket.upload(filename, options, (err, metadata, response)=>{
....
});
你应该看看