小编Wil*_*iro的帖子

从Google Cloud存储中读取图像并使用Google Cloud功能发送

我想执行以下操作:创建Google云功能(http触发),只需从存储桶(Google云端存储)中读取图像文件并将其作为响应发送.

我尝试了一些组合,我认为它应该是这样的:

'use strict';
const gcs = require('@google-cloud/storage')();

exports.sendImage = function sendImage(req, res) {
    let bucket = gcs.bucket('my-bucket-name');
    let myImage = bucket.file('my-image-file.jpg');


    res.contentType('image/jpeg');
    res.end(myImage, 'binary');
};
Run Code Online (Sandbox Code Playgroud)

上面的函数成功部署但是当我使用url(在浏览器上)触发它时,它没有显示任何结果.

我这样做很简单,因为如果它适用于一个图像,我可以改进代码来调用任何图像.

我的最终目标是获得类似于此帖所示的内容:https: //medium.com/google-cloud/uploading-resizing-and-serving-images-with-google-cloud-platform-ca9631a2c556

但是在Google Cloud Functions上运行.如果我设法发送一个简单的图像,我可以使用一些模块,如node-image-resize到最终结果.

node.js google-cloud-storage google-cloud-functions

2
推荐指数
1
解决办法
3134
查看次数