I am having the opposite as this issue: issues deleting an image using Cloud Functions for Firebase and @google-cloud/storage
(for the record, I have tried all things suggested there).
Basically I have a known file path, then a cloud function triggered by a database event.
I can initialise a bucket, get a file as well as its name, but then when I try and download it I get API Error: not found.
Here is my code:
module.exports = (orgID, reportID) => {
const bucket = gcs.bucket("MY_PROJECT.appspot.com");
const filePath = `/safety_hotline/${orgID}/${reportID}`;
const file = bucket.file(filePath);
// the name is shown correctly in the console
console.log(file.name);
const tempLocalFile = path.join(os.tmpdir(), filePath);
const tempLocalDir = path.dirname(tempLocalFile);
return mkdirp(tempLocalDir)
.then(() => {
// Download file from bucket.
return file.download({ destination: tempLocalFile });
})
.then(() => {
console.log("file downloaded succesfully");
})
.catch(err => {
console.log(err);
});
}
You can see I get the console log of the file name, so I don't understand why I can't then download it? Any advice would be amazing, thanks!
Edit: edited code a bit for clarity