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

90
Visualizações
amazon s3.upload is taking time

I am trying to upload file to s3, before that I am altering the name of the file. Now I am accepting 2 files from request form-data object, renaming the filename, and uploading the file to s3. And end of the task I need to return the renamed file list which is uploaded successfully.

I am using S3.upload() function. But the problem is, the variable which is assigned as empty array initially, that will contain the renamed file list. But the array is returning empty response. The s3.upload() is taking much time. is there any probable solution where I can store the file name if upload is successful and return those names in response.

Please help me to fix this. The code looks like this,

      if (formObject.files.document && formObject.files.document.length > 0) {
        const circleCode = formObject.fields.circleCode[0];
        let collectedKeysFromAwsResponse = [];
        formObject.files.document.forEach(e => {
          const extractFileExtension = ".pdf";
          if (_.has(FILE_EXTENSIONS_INCLUDED, _.lowerCase(extractFileExtension))) {
            console.log(e);
            //change the filename
            const originalFileNameCleaned = "cleaning name logic";
            const _id = mongoose.Types.ObjectId();
            const s3FileName = "s3-filename-convension;
            console.log(e.path, "", s3FileName);
            const awsResponse = new File().uploadFileOnS3(e.path, s3FileName);
            if(e.hasOwnProperty('ETag')) {
              collectedKeysFromAwsResponse.push(awsResponse.key.split("/")[1])
            }
          }
        });
      };
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

use await s3.upload(params).promise(); is the solution.

about 4 years ago · Juan Pablo Isaza Relatório

0

Use the latest code - which is AWS SDK for JavaScript V3. Here is the code you should be using

// Import required AWS SDK clients and commands for Node.js.
import { PutObjectCommand } from "@aws-sdk/client-s3";
import { s3Client } from "./libs/s3Client.js"; // Helper function that creates Amazon S3 service client module.
import {path} from "path";
import {fs} from "fs";

const file = "OBJECT_PATH_AND_NAME"; // Path to and name of object. For example '../myFiles/index.js'.
const fileStream = fs.createReadStream(file);

// Set the parameters
export const uploadParams = {
  Bucket: "BUCKET_NAME",
  // Add the required 'Key' parameter using the 'path' module.
  Key: path.basename(file),
  // Add the required 'Body' parameter
  Body: fileStream,
};


// Upload file to specified bucket.
export const run = async () => {
  try {
    const data = await s3Client.send(new PutObjectCommand(uploadParams));
    console.log("Success", data);
    return data; // For unit tests.
  } catch (err) {
    console.log("Error", err);
  }
};
run();

More details can be found in the AWS JavaScript V3 DEV Guide.

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