Open FaizanAshiq opened 3 months ago
with node server.js everything works fine. but when I run it with bun server.js it got stuck on line const result = await s3.send(command); when I send a request from Postman. I can see the command log but cannot see the done log.
Is the uploadImage
function being await
'?
Otherwise, this mostly appears to be a formatting difference between Bun and Node for Buffer
objects and potentially classes as well
Via @mangs in the discord: https://discord.com/channels/876711213126520882/1149339379446325248/1218435079802716221
mangs — Today at 10:46 PM those outputs are the same, convert decimal to hex and you get the same values https://www.binaryhexconverter.com/decimal-to-hex-converter
In the future please use code blocks on GitHub to format your code, it's difficult to see what you mean exactly
Yes, I am awaiting the uploadImage function. the same code is working when I run with node
but stuck on const result = await s3.send(command);
when I run this using Bun
here is my code.
// -----------------------------------------------------------
// imports
// -----------------------------------------------------------
const sharp = require('sharp');
const {
S3Client,
PutObjectCommand,
DeleteObjectCommand,
} = require('@aws-sdk/client-s3');
const AppError = require('../utils/appError');
// -----------------------------------------------------------
// configurations
// -----------------------------------------------------------
const s3 = new S3Client({
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
region: process.env.AWS_REGION,
});
// -----------------------------------------------------------
// exports
// -----------------------------------------------------------
exports.uploadImage = async (path, name, next) => {
const fileBuffer = await sharp(path).toBuffer();
const params = {
Body: fileBuffer,
Bucket: process.env.AWS_BUCKET_NAME,
ContentType: 'image/jpeg',
Key: name,
};
// Uploading files to the bucket
const command = new PutObjectCommand(params);
const result = await s3.send(command);
if (result.$metadata.httpStatusCode !== 200) {
return next(new AppError('Image update failed', 500));
}
const url = `https://${process.env.AWS_BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${name}`;
return url;
};
exports.deleteImage = async (Key) => {
const params = {
Bucket: process.env.AWS_BUCKET_NAME,
Key,
};
const command = new DeleteObjectCommand(params);
const result = await s3.send(command);
return result;
};
@Jarred-Sumner I am still struggling to figure out what's wrong. The same code works for node
but not for bun
.
a few screenshots to understand
@Jarred-Sumner I am still struggling to figure out what's wrong. The same code works for
node
but not forbun
.a few screenshots to understand
same problem
Same issue +1
What version of Bun is running?
1.0.31
What platform is your computer?
Linux 6.5.0-1014-aws x86_64 x86_64
What steps can reproduce the bug?
first of all my code for aws image upload is:
I am running the server using two commands for testing. first command:
node server.js
second command:bun server.js
withnode server.js
everything works fine. but when I run it withbun server.js
it got stuck on lineconst result = await s3.send(command);
when I send a request from Postman. I can see thecommand
log but cannot see thedone
log.moreover the logs for both cases are here.
logs when I run it with bun
logs when I run it with node.
Additional information
You can see commands are different here. and the buffer is also different.