1

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"}) 
  • it seems that this may have to do with how temp files are handled in GCP (i.e. they are not real persistent files on disk). There's a few similar reports: https://stackoverflow.com/questions/51297006/upload-image-from-google-cloud-function-to-cloud-storage https://stackoverflow.com/questions/49396849/google-cloud-functions-upload-to-google-cloud-storage-via-http Not exactly sure why Storage API may have an issue with this – user1552175 Dec 28 '18 at 18:51

0 Answers0