本文介绍了从我的节点服务器上的 AWS S3 获取签名 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
已解决:
我想从我的 亚马逊 S3 服务器 获得一个签名网址.我是 AWS 的新手.我在哪里设置我的 secret-key 和 access_id_key 以便 S3 识别来自我的服务器的请求.
I want to get a signed URL from my amazon S3 server. I am new to AWS. where do i set my secret-key and access_id_key so that S3 identifies request from my server.
var express=require('express');
var app=express();
var AWS = require('aws-sdk')
, s3 = new AWS.S3()
, params = {Bucket: 'my-bucket', Key: 'path/to/key', Expiration: 20}
s3.getSignedUrl('getObject', params, function (err, url) {
console.log('Signed URL: ' + url)
})
app.listen(8000)
推荐答案
如果您正在使用多个存储桶,您还可以为每个存储桶设置凭据,您只需要将凭据传递到 S3 对象的构造函数中,例如所以:
You can also set the credentials for each bucket if you are working with multiple buckets, you just need to pass the credentials into the constructor of the S3 object, like so:
var AWS = require('aws-sdk');
var credentials = {
accessKeyId: AWS_CONSTANTS.S3_KEY,
secretAccessKey: AWS_CONSTANTS.S3_SECRET,
region: AWS_CONSTANTS.S3_REGION
};
var s3 = new AWS.S3(credentials);
var params = {Bucket:'bucket-name', Key: 'key-name', Expires: 20};
s3.getSignedUrl('getObject', params, function (err, url) {
console.log('Signed URL: ' + url);
});
这篇关于从我的节点服务器上的 AWS S3 获取签名 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!