使用预签名URL通过cURL将文件上传到S3

问题描述:

我正在获取一个预签名的URL,以将文件上传到S3存储桶中.

I'm getting a pre-signed URL to upload a file on S3 bucket.

这是curl命令:

$ curl -v -T ./dansero.jpg'

$curl -v -T ./dansero.jpg 'https://ss-files-dev.s3.ap-southeast-2.amazonaws.com/dansero.jpg\?AWSAccessKeyId\=AKIAIT6VM43PPNS43Y7Q\&Expires\=1531973770\&Signature\=hNvG5rnICkk58mMBLeMgHGDZ93c%3D'

这给了我错误:

AccessDenied 访问被拒绝

AccessDeniedAccess Denied

这是我的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.