I'd like to do the following: Create a Google Cloud Function (http triggered) that simply read an image file from a bucket (Google Cloud Storage) and send it as a response.
I've tried some combinations and I think that it should be something like that:
'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');
};
The function above deploys successfully but when I trigger it just using the url (on browser) it shows no results.
I'm doing that as simple as possible because if it works with one image, I can improve the code to call any image.
My final goal is to have something similar to that showed on this post: https://medium.com/google-cloud/uploading-resizing-and-serving-images-with-google-cloud-platform-ca9631a2c556
But running on Google Cloud Functions. If I manage to send a simple image, I can use some module such as node-image-resize to the final result.