问题描述
我正在获取一个预签名的URL,以将文件上传到S3存储桶中.
I'm getting a pre-signed URL to upload a file on S3 bucket.
这是curl命令:
这给了我错误:
这是我的node.js生成的预签名URL
Here my node.js generation of the presigned URL
var AWS = require('aws-sdk');
const s3 = new AWS.S3({
accessKeyId: 'aaa',
secretAccessKey: 'bbb+oeyjn8zGANuDyCIY',
region: 'ap-southeast-2'
});
const params = {
Bucket: 'ss-files-dev',
Key: 'dansero.jpg'
};
});
s3.getSignedUrl('putObject', params, function(err, urlsign) {
if (err) console.log(err);
console.log(urlsign);
});
那么URL生成或curl中的问题在哪里?谢谢
So where is my problem in the URL generation or the curl?thanks
推荐答案
我看不到签名请求部分.确保获得放置对象的签名URL.它是我脚本中的有效代码:
I can't see the sign request part. Make sure get signed URL for put object.It is working code from my script:
s3.getSignedUrl('putObject', params, function(err, urlsign) {
if (err) console.log(err);
var output = {
url: urlsign
};
cb(null, output);
});
尝试通过简单的put请求将对象放入存储桶中,如下所示:
Try put the object into your bucket by simple put request like this:
var req = http.request({
hostname: 's3.amazonaws.com',
port: 80,
path:{YOURPRESIGNEDURL}.replace('https://s3.amazonaws.com', ''),
method: 'PUT',
}, function(res) {
最后,请确保以下几点:
Finally, make sure about the following things:
1-用户策略,并为您的密钥设置IAM.您应该具有放置这样的对象的权限:
1-User policy and right IAM for your key. You should have the permission to put objects like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt14546345345",
"Effect": "Allow",
"Action": [
"s3:Put*"
],
"Resource": [
"arn:aws:s3:::myBucket/*"
]
}
]
}
2-我认为您应该在curl请求中传递-X PUT.
2- I think you should pass -X PUT in your curl request.
这篇关于使用预签名URL通过cURL将文件上传到S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!