I have been uploading files to google cloud storage from my node js server for quite a long time now. But sometimes the upload fails. Error message returned is something like:
{
reason:"badRequest",
code: 400,
message: "Invalid upload request"
}
It happens randomly, means once in around 25-30 days for some time and then is resolved automatically. It's kind of weird and searching for it didn't give any solution or the reason.
The upload request is sent for two files in parallel having exactly the same data. one was uploaded successfully and other failed.
code used:
const file = bucket.file(`data/${id}/${version}/abc.json`);
const dataBuffer = Buffer.from(JSON.stringify(dataToUpload));
file.save(dataBuffer, storageConfig)
.then(() => callback(null, true))
.catch(err => callback(err, null));
where storageConfig is
{
"contentType": "application/json",
"cacheControl": "public, max-age=600, s-maxage=3, no-transform"
}
and the second file name which is stored is
const file = bucket.file(`data/${id}/latest/abc.json`);
I am not able to find any reason for it and unable to handle it. It crashed my related systems as they require that second file.