Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
How to Upload File to AWS S3 Bucket via pre signed URL in Node.js

I am uploading file to S3 bucket using S3 upload function in Node.js. The frontend is built on Angular. But now the client's requirement is that all uploads should direct to s3 bucket via a presigned URL. Does this because of any security concern? The Code that i am currently using to upload files to S3 Bucket is:

async function uploadFile(object){
//object param contains two properties 'image_data' and 'path'
  return new Promise(async(resolve, reject) => {
        var obj = object.image_data;
        var imageRemoteName = object.path+'/'+Date.now()+obj.name;
        AWS.config.update({
          accessKeyId: ACCESS_KEY,
          secretAccessKey: SECRET_KEY,
          region: REGION
        })

        var s3 = new AWS.S3()
        s3.upload({
          Bucket: BUCKET,
          Body: obj.data,
          Key: imageRemoteName
        })
        .promise()
        .then(response => {
            console.log(`done! - `, response)
            resolve(response.Location)
        })
        .catch(err => {
            console.log('failed:', err)
        })

  })
}

Any Help will be appreciated, Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Security wise it doesn't make a difference whether you call upload or first create a pre-signed URL, as long as the code you showed does not run within your Angular application, meaning on the client. In that case every client of your application has access to your AWS access key, and secret key. Still, swapping upload with a pre-signed URL won't solve the problem in this case. However, if you use a server such as express and that's where this code is running, you're basically fine.

AWS provides instructions on how to upload objects using a pre-signed URL. The basic steps are:

import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
const s3Client = new S3Client({ 
    accessKeyId: ACCESS_KEY,
    secretAccessKey: SECRET_KEY,
    region: REGION 
});

/* ... */

const command = new PutObjectCommand({
  Bucket: BUCKET,
  Body: obj.data,
  Key: imageRemoteName
});

// upload image and return a new signed URL, 
// with expiration to download image, if needed. 
// Otherwise you can leave `signedUrl` unused.
const signedUrl = await getSignedUrl(s3Client, command, {
  expiresIn: 3600,
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda