Git Product home page Git Product logo

Comments (3)

Jarred-Sumner avatar Jarred-Sumner commented on July 20, 2024 1

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

from bun.

FaizanAshiq avatar FaizanAshiq commented on July 20, 2024

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;
};

from bun.

FaizanAshiq avatar FaizanAshiq commented on July 20, 2024

@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

code

postman

node

from bun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.