【问题标题】:node js aws-sdk connect节点 js aws-sdk 连接
【发布时间】:2021-09-06 22:21:40
【问题描述】:

我有一个像 aruba-get-rds-backups.getaws.arubanetworks.com/sp/ 这样的 s3 存储桶,其中 aruba-get-rds-backups.getaws.arubanetworks.com 是存储桶名称,/sp 是一种子文件夹 如何使用 nodejs 中 aws-sdk 的 getObject 方法访问存储桶中 /sp 文件夹内的文件

【问题讨论】:

    标签: node.js aws-sdk


    【解决方案1】:
    async function getS3Obj(bucketName, bucketKey) {
        let AWS = require("aws-sdk");
        let s3 = new AWS.S3({ apiVersion: "2006-03-01" }); // provide credentials, if needed
    
        const params = {
            Bucket: bucketName,
            Key: bucketKey,
        };
        let content = await s3.getObject(params).promise();
    
        // assuming here you're downloading ascii file
        return content.Body!==undefined ? content.Body.toString() : null;
    }
    
    ( async () =>{
    
        try {
            
            // your call will likely to be something...
            const content = await getS3Obj("bucketName", "sp/file.txt");
            console.log(content);
        } catch (error) {
            console.log(error);
        }
    })();
    

    【讨论】:

    • 好点我会编辑退货声明
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 2021-07-01
    • 2012-02-08
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多