第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

將 s3 對(duì)象數(shù)據(jù)放入數(shù)組 - 節(jié)點(diǎn)

將 s3 對(duì)象數(shù)據(jù)放入數(shù)組 - 節(jié)點(diǎn)

白板的微信 2022-05-14 15:18:44
我正在嘗試從 S3 對(duì)象中獲取數(shù)據(jù)并將其放入數(shù)組中。我計(jì)劃通過這個(gè)數(shù)組映射并在網(wǎng)格/列表中的 React 前端顯示數(shù)據(jù)。不過,我正在為嵌套函數(shù)而苦苦掙扎,因此我將不勝感激。const dataFromS3 = async (bucket, file) => {let lines = [];const options = {    Bucket: bucket,    Key: file  };s3.getObject(options, (err, data) => {if (err) {  console.log(err);} else {  let objectData = data.Body.toString('utf-8');  lines.push(objectData);  console.log(lines);  return lines;}  });};格式化有點(diǎn)奇怪,但這是我從 s3 獲取數(shù)據(jù)的功能。我想以數(shù)組的形式獲取此函數(shù)的輸出并將其傳遞給我正在測(cè)試的“/”路由:app.get('/', async (req, res, next) => {try {    let apolloKey = await dataFromS3(s3Bucket, apolloKeywords);    res.send(apolloKey);  } catch (err) {    console.log('Error: ', err);  }});似乎s3.getObject函數(shù)中的行的返回值需要在第一個(gè)函數(shù)中返回,以便我可以在 app.get 中訪問它,但經(jīng)過一些嘗試后我似乎無法做到這一點(diǎn)。如果我在datafromS3()的末尾返回它,那么行中的值將變成一個(gè)空數(shù)組,并且我找不到返回它的方法。我也嘗試使用此處找到的方法使用 Promise - How to get response from S3 getObject in Node.js? 但我得到一個(gè) TypeError: Converting Circular Structure to JSON ...
查看完整描述

1 回答

?
jeck貓

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊

你需要讓你的 dataFromS3 像 htis 一樣運(yùn)行。你沒有從中返回任何東西。AWS 還提供了基于 Promise 的功能。


const dataFromS3 = async (bucket, file) => {

  const lines = [];


  const options = {

    "Bucket": bucket,

    "Key": file

  };


  const data = await s3.getObject(options).promise();

  const objectData = data.Body.toString("utf-8");

  lines.push(objectData); // You might need to conversion here using JSON.parse(objectData);

  console.log(lines);

  return lines;

};


查看完整回答
反對(duì) 回復(fù) 2022-05-14
  • 1 回答
  • 0 關(guān)注
  • 123 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)