I would like to implement the following process on cloud functions (TypeScript).
- Get the image by URL
- Save image to Cloud Storage
- Get URL of the image saved in the firestore
I am trying to move it with the following code, there is 2 problem.
- It takes a long time to save the data (about 5 minutes)
- URL is not issued to the saved image
Code:
const bucket = admin.storage().bucket();
const url = 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
request(
{ method: 'GET', url: url, encoding: null },
async function (error, response, body) {
if (!error && response.statusCode === 200) {
const file = bucket.file('test/test.png');
const metadata = {
contentType: 'image/png'
};
try {
await file.save(body, metadata);
} catch (err) {
console.log(err);
}
}
}
);
It would be greatly appreciated if you could explain the details.