IBM / ibm-cos-sdk-js

ibm-cos-sdk-js
Apache License 2.0
38 stars 19 forks source link

Error handling when a endpoint / bucket values are not related to the accessKeyID / secretAccessKey #95

Closed fernandovch closed 1 year ago

fernandovch commented 1 year ago

Description

I'm using the library ibm-cos-sdk, and when I'm calling the upload or the putObject function to send a file into a COS. At first, I was having some issues because of the configuration object, the values were wrong. After that, I started testing the settings with different values just to check if the error handling was working.

That's when I realized that if I set the correct accessKeyID / secretAccessKey values, but with a different endpoint/bucket name (The bucket name and the endpoint exists), I still get the uploaded successfully log into the console even that the file was not uploaded into the COS. I try to read the data response, but I'm only getting (using upload function) /// there was no file uploaded.

{ "ETag":"\"d29b3fd3a67d5b3336bc61966b2cf46d\"", "Location":"https://bucket-name-wrong.s3.us-east.cloud-object-storage.appdomain.cloud/9ee8fcb6-9d09-49e2-83f1-a114200ed0fe.xlsx", "key":"9ee8fcb6-9d09-49e2-83f1-a114200ed0fe.xlsx", "Key":"9ee8fcb6-9d09-49e2-83f1-a114200ed0fe.xlsx", "Bucket":"bucket-name-wrong" }

and with the putObject the response only has

{ "ETag":"\"d29b3fd3a67d5b3336bc61966b2cf46d\" }

So, my question is, is there a way to know if the file is been successfully uploaded?

const cos = new COS.S3({ accessKeyId: 'ce6e8 .........edf', /// CORRECT VALUE secretAccessKey: "7d874d.......afd6", /// CORRECT VALUE endpoint: 's3.us-east.cloud-object-storage.appdomain.cloud' /// WRONG VALUE });

cos.upload({ Bucket: 'bucket-name-wrong', Key: fileName, Body: file.buffer }).promise() .then((data) => { logger.info(File: ${fileName} uploaded successfully to COS!); }) .catch((e) => { throw Error: ${e.code} - ${e.message}\n; });