I have a Google Cloud function that take the screenshot of a url and i need to upload that image to google cloud bucket from google cloud function
I have tried uploading it using the code given below but it does not work and gives error
/**
* Responds to any HTTP request.
*
* @param {!express:Request} req HTTP request context.
* @param {!express:Response} res HTTP response context.
*/
exports.takeScreenshot = (req, res) => {
const Screenshot = require('url-to-screenshot')
const Storage = require('@google-cloud/storage')
const fs = require('fs')
const bucketName="screenshot_bucket_mujahid"
new Screenshot('http://ghub.io/')
.width(800)
.height(600)
.capture()
.then(img =>
Storage
.bucket(bucketName)
.upload(img,"mujahid.jpg"))
console.log('open example.png')
})
let message = req.query.message || req.body.message || 'Hello World!';
res.status(200).send(message);
};