8

解决了:

我想从我的amazon S3 服务器获取签名 URL。我是AWS新手。我在哪里设置我的密钥access_id_key以便S3识别来自我的服务器的请求。

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)
4

2 回答 2

5

如果您使用多个存储桶,您还可以为每个存储桶设置凭证,您只需将凭证传递给 S3 对象的构造函数,如下所示:

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);
});
于 2016-09-15T23:45:17.170 回答
4

后来我解决了我的问题。这非常有帮助 http://aws.amazon.com/sdkfornodejs/此外,您还可以将您的凭据硬编码为

var express=require("express");
var app=express();

var AWS = require('aws-sdk')
, s3 = new AWS.S3()
, params = {Bucket:'your-bucket-name on s3', Key: 'key-name-on s3 you want to store under', Expires: 20}

AWS.config.update({accessKeyId: 'Your-Access-Key-Id', secretAccessKey:     
'Your-secret-key'});

AWS.config.region = 'us-west-2';


s3.getSignedUrl('getObject', params, function (err, url) {
console.log('Signed URL: ' + url);
});

app.listen(8000);
于 2014-06-07T10:57:56.833 回答