相关疑难解决方法(0)

nodejs 如何从 aws s3 存储桶中获取 JSON 而不是 Buffer

我有一个 .json 文件存储在 S3 存储桶中,现在我想用 nodejs 下载 json 文件。我写了以下代码:

const bucket = "s3bucketname";

const AWS = require('aws-sdk');
const S3= new AWS.S3();
exports.handler = async (event, context, callback) => {
    var transcript = await download();
    console.log(transcript);
}

async function download(){
  try {
    // Converted it to async/await syntax just to simplify.
    const data = await S3.getObject(
    {   Bucket: bucket, 
        Key: "Test.json",
        //ResponseContentType: 'application/json'
    }).promise();

    console.log(data);
    return {
      statusCode: 200,
      body: JSON.stringify(data)
    }
  }
  catch (err) {
    return {
      statusCode: err.statusCode || …
Run Code Online (Sandbox Code Playgroud)

javascript json amazon-s3 amazon-web-services node.js

9
推荐指数
2
解决办法
6556
查看次数

如何将文件缓冲区转换为 <img> 标签 src?

我正在开发一个应用程序,使用 Node.js 作为后端,并作为我的前端进行反应。现在我创建了一个上传文件并将其作为缓冲区类型存储在 mongodb 中的路由。我的问题是,当我在 React 应用程序中收到这些数据时,如何使用这些数据将其转换为 html 图像标签中的源属性?当我查看 mongodb 指南针时,文件属性如下所示:(非常长的字符串)

在此输入图像描述 当我查看对象本身时,当我得到它作为响应时,它看起来像这样:(数字数组); 在此输入图像描述

我尝试使用

  <img
      src={`data:${props.images[0].mimetype};base64,${props.images[0].file.data}`}
    />
Run Code Online (Sandbox Code Playgroud)

但它没有用..

在此输入图像描述

如果有人能给出答案,真的很感激!

猫鼬模型:

   images: [
    {
    file: { type: Buffer },
     filename: { type: String },
    mimetype: { type: String }
   }
  ]
Run Code Online (Sandbox Code Playgroud)

节点.js

 var multer = require('multer');

 var upload = multer({
 limits: {
  fileSize: 1000000
}
});

 app.post('/upload', upload.single('file'), async (req, res) => {
 try {
 const file = {
  file: req.file.buffer,
  filename: req.file.originalname,
  mimetype: req.file.mimetype
};
// console.log(req.file.buffer.toString('base64'));
const product = new …
Run Code Online (Sandbox Code Playgroud)

buffer mongoose mongodb node.js reactjs

4
推荐指数
1
解决办法
1万
查看次数

从 s3 读取数据:s3.getObject 不是函数

我正在尝试从 S3 读取 txt 文件来构建 Alexa 的响应。在 Lambda 中测试代码时,我收到此错误。谁能看到我哪里出错了?

错误

Error handled: s3.getObject is not a function
Run Code Online (Sandbox Code Playgroud)

我已经安装了“aws-sdk”,并且需要该模块位于我的技能的 index.js 顶部

const s3 = require('aws-sdk/clients/s3')
Run Code Online (Sandbox Code Playgroud)

处理程序代码。为了强调这一点,我使用 Async/Await 并在下面的 goGetS3 函数中返回一个 Promise。

const ChooseStoryIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
      handlerInput.requestEnvelope.request.intent.name === 'ChooseStoryIntent';
  },
  async handle(handlerInput) {
    let speechText;
    let options = {
      "Bucket": "stores",
      "Key": "person.txt"
    }
    await goGetS3(options)
      .then((response) =&gt; {
        console.log(response),
        console.log(response.Body.toString()),
          speechText = response
      })
      .catch((err) =&gt; {
        console.log(err)
        speechText = 'something wrong getting the …
Run Code Online (Sandbox Code Playgroud)

alexa-skills-kit

3
推荐指数
1
解决办法
9847
查看次数