In my node.js server I have a post
request making 2 uploads to google cloud storage--each into a different bucket.
When I tested the functionality, I was able to successfully upload 2 files to 2 different buckets, but upon the next test, 1 of the 2 uploads is failing and throwing an error: Error: Could not load the default credentials
.
Why would it fail on the second test on only 1 of the uploads?
Why would it say the credentials can't be loaded if it's a fully public bucket (all users have full object access to read/write/admin)?
app.post("/upload", upload.single("image"), (req, res) => {
//this takes an image file and uploads it
async function uploadFile() {
await storage.bucket(bucketName).upload(imagePath, {destination: imagePath})
}
uploadFile().catch(console.error);
//this resizes the image
Jimp.read(imagePath, (err, img) => {
if (err) throw err
img.resize(Jimp.AUTO, 300).write(imgTitle + "-thumb.jpg")
})
//this uploads the resized image
async function uploadThumb() {
await storage.bucket(thumbs).upload(imgTitle + "-thumb.jpg", {destination: cat + "/" + subCat + "/" + imgTitle + "-thumb.jpg"})
}
setTimeout(() => { //this timeout waits 2 seconds for JIMP to finish processing the image
uploadThumb().catch(console.error);
}, 2000)
});
I'm hoping someone can explain why this stopped working after the first test. The function that uploads the resized image works in both tests, but the function that uploads the original file fails on the 2nd test throwing the error: Error: Could not load the default credentials
UPDATE
After many tests, I have possibly deduced that this is a file size issue. The thumbnail upload works every time, while the full size image fails when its size reaches ~2-3MB. Reading the GCS docs, it says that 5TB is the maximum single file upload limit, so I don't know why there is an issue with a few MB. I do not want to lower the image size/resolution as they are art works that will need to be viewed at full size (that's exactly why I'm creating the thumbnails in the first place).