I'm getting the error "Uncaught Exception: ApiError: Not Found" with google cloud storage sdk whenever I use createWriteStream (I'm using nodejs/typescript).
Initially in my code I was setting the bucket as ${anization}/${fileName}
. But, then I saw in the logs the url google was trying to use to make the request, /{anizationId}/orders.csv/o/{anizationId}%2Forders.csv?alt=media (I'm omitting the actual anization id). It appears that's not using the bucket but just duplicating the fileName. So, I set the filename to orders.csv in case it was the / I had in there, and it's still generating the exact same request.
When I output the name and bucket of the file object before calling createWriteStream they're both showing the correct values as well.
const bucketName = 'shadowscore-data-import-production';
const bucket = this.storage.bucket(bucketName);
const newFilePath = 'orders.csv';
const newFile = bucket.file(newFilePath);
const writeStream = newFile.createWriteStream({
resumable: false,
});
return new Promise((resolve, reject) => {
stream.on('error', (error) => {
writeStream.destroy(error);
reject(error);
});
writeStream.on('error', (error) => {
stream.unpipe();
reject(error);
});
writeStream.on('finish', () => resolve(newFilePath));
stream.pipe(writeStream);
});