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

129
Views
La función auxiliar no devuelve la respuesta pero muestra el resultado con la función

Tengo esta función auxiliar:

 const listFileKeysInSpaceByPrefix = async (prefix) => { var params = { Bucket: process.env.S3_BUCKET_NAME, Prefix: prefix, }; let fileKeys; await s3.listObjects(params, function (err, data) { if (err) { console.log(err, err.stack); next(err); } let keys = []; data["Contents"].forEach(function (obj) { keys.push(obj.Key); }); console.log("key1", keys); fileKeys = keys; }); return fileKeys; };

Y llamé a la función auxiliar dentro de una ruta como esta:

 const keyToBeDeleted = await listFileKeysInSpaceByPrefix(uploadSpaceFolder); console.log("keys",keyToBeDeleted);

Sin embargo, el resultado en mi consola se ve así:

 keys undefined key1 ['adamter/rr0.png', 'adamter/rt0.png']

Necesito obtener la matriz en mi respuesta cuando llamo a la función, pero parece que no encuentro una forma de evitar esto.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pruebe con la función de devolución de llamada.

 const listFileKeysInSpaceByPrefix = (prefix, callBackFn) => { var params = { Bucket: process.env.S3_BUCKET_NAME, Prefix: prefix, }; s3.listObjects(params, function (err, data) { if (err) { console.log(err, err.stack); next(err); } let keys = []; data["Contents"].forEach(function (obj) { keys.push(obj.Key); }); console.log("key1", keys); callBackFn(keys); }); }; function yourFunction() { function callBackFn(keyToBeDeleted) { // access keyToBeDeleted // add your logic here } listFileKeysInSpaceByPrefix(uploadSpaceFolder, callBackFn); }
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!