使用预签名 URL 通过 cURL 将文件加载到 S3 [英] Ppload file to S3 via cURL using presigned URL

查看:54
本文介绍了使用预签名 URL 通过 cURL 将文件加载到 S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个预先签名的 URL,用于在 S3 存储桶上上传文件.

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

这是 curl 命令:

this is the curl command:

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

这给了我错误:

<Error>
  <Code>AccessDenied</Code>
  <Message>Access Denied</Message>
</Error>

这里是我的 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);
        });

尝试通过像这样的简单放置请求将对象放入您的存储桶中:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆