Creating a signed S3 URL with Javascript

前端 未结 3 968
情书的邮戳
情书的邮戳 2021-02-04 18:54

I am attempting to create a signed S3 URL using Javascript & NodeJS. I have used this specification.

var crypto     = require(\'crypto\'),
    date       =          


        
3条回答
  •  梦谈多话
    2021-02-04 19:08

    My implementation using AWS-SDK and Rx.

    import AWS from "aws-sdk"
    import Rx from 'rx'
    
    /*
    * Credentials could be loaded from env variables
    * http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-environment.html
    * */
    
    const s3 = new AWS.S3({apiVersion: '2006-03-01'});
    
    export function getS3SignedImage(objectKey) {
        return Rx.Observable.create(function (observer) {
            s3.getSignedUrl('getObject',{
                Bucket: process.env.AWS_BUCKET,
                Key: objectKey
            }, (err, data) => {
                if (err) {
                    return observer.onError(err);
                }
                observer.onNext(data);
                observer.onCompleted();
            });
        });
    }
    

提交回复
热议问题