0
votes

I've realtime databse when user can write url of an image. When created/updated I'm already able to trigger a cloud function that can read the url of the image from realtime database

I now need to download the image from web (so it's not an upload) and save it on firebase storage.

I cannot find a single example of fetching a web resource and store into firebase storage.

Can please you point me to right solution?

My idea was to reacting to create/update of the url on the db, then fetch (can I use fetch npm package??) and then save the fetched content into the storage bucket using url as key

But fetch + save fetched data is what I am not able to do now

1

1 Answers

1
votes

Before someone closes this question because is 'off-topc', I write my own solution.

const bucket = admin.storage().bucket();

const axios = require('axios');

const response = await axios.post(BASE_URL, data_to_post, config);
console.log("Response.status", response.status);

const cache_file_name = `page-cache/page-${pageNumber}.html`;
const cache_file_options = { 
    metadata : {
        contentType : 'text/html' 
    }
};
const cache_file = bucket.file(cache_file_name);

await cache_file.save(response.data, cache_file_options);