Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

85
Views
amazon s3.upload está tardando

Estoy tratando de cargar un archivo en s3, antes de eso estoy alterando el nombre del archivo. Ahora estoy aceptando 2 archivos del objeto de datos de formulario de solicitud, renombrando el nombre del archivo y cargando el archivo en s3. Y al final de la tarea, necesito devolver la lista de archivos renombrados que se cargó correctamente.

Estoy usando la función S3.upload() . Pero el problema es que la variable que se asigna inicialmente como matriz vacía, contendrá la lista de archivos renombrados. Pero la matriz devuelve una respuesta vacía. El s3.upload() está tomando mucho tiempo. ¿Hay alguna solución probable en la que pueda almacenar el nombre del archivo si la carga se realiza correctamente y devolver esos nombres en respuesta?

Por favor, ayúdame a arreglar esto. El código se ve así,

 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 answers
Answer question

0

use await s3.upload(params).promise(); es la solución

about 4 years ago · Juan Pablo Isaza Report

0

Utilice el código más reciente, que es AWS SDK para JavaScript V3 . Aquí está el código que debe usar

 // 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();

Puede encontrar más detalles en la Guía para desarrolladores de AWS JavaScript V3 .

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!