栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何从Node.js中的S3 getObject获得响应?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何从Node.js中的S3 getObject获得响应?

当执行

getObject()
从S3
API,按照文档文件的内容都位于
Body
属性,您可以从您的样品输出看到。您应该具有类似于以下内容的代码

const aws = require('aws-sdk');const s3 = new aws.S3(); // Pass in opts to S3 if necessaryvar getParams = {    Bucket: 'abc', // your bucket name,    Key: 'abc.txt' // path to the object you're looking for}s3.getObject(getParams, function(err, data) {    // Handle any error and exit    if (err)        return err;  // No error happened  // Convert Body from a Buffer to a String  let objectData = data.Body.toString('utf-8'); // Use the encoding necessary});

您可能不需要从

data.Body
对象创建新的缓冲区,但是如果需要,可以使用上面的示例来实现。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/394680.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号