New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@aws-sdk/client-s3 producing error on image upload #4626
Comments
Hi @himyuni, thanks for opening this issue. I agree that getting UnknownError as error message is not helpful. I will bring this into the team to discuss how the desserialization for this type of errors can be improved. However, something you can do as of right now is to log the response before it is parsed, and there you will the whole message that comes with the response. // 1 - First create a custom handler
class MyCustomHandler extends NodeHttpHandler {
handle(request, {abortSignal}) {
const promise = super.handle(request, {abortSignal});
return promise.then((response) => {
const body = response.response.body;
console.log((typeof body));
(async () => {
console.log(await Promise.resolve(body))
})();
return response;
});
}
}
// 2 - Then, use the custom handler in the client
const client = new S3({
region: 'us-east-2',
requestHandler: new MyCustomHandler()
})
// 3 -
const upload = async (name, file, bucket=process.env.TEST_BUCKET) => {
const uploader = {
Bucket: bucket,
Key: name,
Body: Buffer.from(file)
}
const upload = await client.putObject(uploader);
return {
etag: upload.ETag.replace(/\"/g,""),
location: '',
key: name,
bucket: bucket
}
}
const file = fs.readFileSync('./image.png', {});
const response = await upload(process.env.TEST_KEY, file) Please let me know if that helps. Thanks! |
actually I fixed the issue. after 2 days of debugging. I found The error, it was in the previous line where I called the upload function. but don't know why aws was producing the error. Previous Code After Fix The |
@himyuni thanks for letting me know, and I am glad you get it fixed. If you have any other issues feel free to reach out. Thanks! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Checkboxes for prior research
Describe the bug
trying to upload a image to s3. the error it's generating is horrible, i tried to find the solution everywhere, nothing seems working. The generated error saying its UnknownError. how i am suppose to find the problem and fix it where aws is saying it's a unknown error :D.
SDK version number
@aws-sdk/package-name@3.306.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
14.9.1
Reproduction Steps
Observed Behavior
Expected Behavior
Should've uploaded the image.
Possible Solution
No response
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: