2

tried uploading to s3 in nextjs, is there any way to reduce the bundle size of the aws-sdk ?

...analyze/client.html

upload code

import S3 from 'aws-sdk/clients/s3';

export const uploadS3 = async (file: File) => {
  let type = file.name.split('.').pop().toLowerCase();
  const can = ['jpg', 'png', 'gif', 'svg', 'jpeg', 'webp'];

  if (can.indexOf(type)) {
    const fileName = `content-images/dobda-${Date.now().toString()}.` + type;
    const s3 = new S3({
      region: process.env?.NEXT_PUBLIC_REGION,
      accessKeyId: process.env?.NEXT_PUBLIC_AWS_ACCESS_KEY_ID,
      secretAccessKey: process?.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY,
    });

    const upload = s3.upload({
      Bucket: process.env?.NEXT_PUBLIC_BUKET,
      Key: fileName, 
      Body: file, 
      ContentType: file.type,
      // ACL: 'public-read',
    });

    return await upload.promise()...
  }
};
bootoo
  • 23
  • 3
  • Welcome to Stack Overflow! Please visit the [help center](https://stackoverflow.com/help), take the [tour](https://stackoverflow.com/tour) to see what and [How to Ask](https://stackoverflow.com/questions/how-to-ask). Do some research. If you get stuck, post a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of your attempt, noting input and expected output using the [snippet editor](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do). – Markus Safar Oct 25 '22 at 00:45
  • Please also check [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Markus Safar Oct 25 '22 at 00:45
  • If this is only used on user action, you could dynamically load the library when it's actually needed. – juliomalves Oct 26 '22 at 22:09

0 Answers0