In a Firebase cloud function I download an image from one bucket, create a temporary file (to make modifications) and then attempt to upload it to a different bucket. When doing so, the logs show an ApiError: Not found exception when attempting to upload the temporary file. I can upload the temporary file to the bucket the original file came from without issues.
I was under the assumption that the temporary file was stored in memory but it seems it is somehow linked to the original bucket... Any ideas?
const file = gcs.bucket(object.bucket).file(object.name); //OBJECT IS FROM THE TRIGGER EVENT
const tempLocalFilename = `/tmp/${path.parse(file.name).base}`;
// Download file from bucket.
return file.download({ destination: tempLocalFilename })
.catch((err) => {
console.error('Failed to download file.', err);
return Promise.reject(err);
})
.then(() => {
console.log(`Image ${file.name} has been downloaded to ${tempLocalFilename}.`);
// UPLOADING TO ORIGINAL FILE BUCKET WORKS
return file.bucket.upload(tempLocalFilename, { destination: "test.jpg"
})
// USING THE BELOW INSTEAD RESULTS IN A NOT FOUND EXCEPTION
const newbucket = gcs.bucket("squarenotch-imageserver");
return newbucket.upload(tempLocalFilename, { destination: "test.jpg"})