Amazon s3 使用我自己的域/子域生成AWS S3预签名URL
我正在使用AWS SDK for.NET,目前正在为我的S3存储桶生成预签名URL 我当前获得的URL类似于Amazon s3 使用我自己的域/子域生成AWS S3预签名URL,amazon-s3,pre-signed-url,Amazon S3,Pre Signed Url,我正在使用AWS SDK for.NET,目前正在为我的S3存储桶生成预签名URL 我当前获得的URL类似于https://{bucketname}.s3.amazonaws.com/{FileAndQueryParameters} 我想要的是类似于https://{MyDomainName}/{FileAndQueryParameters} 我已经尝试用我自己的CNAME替换第一个url,指向{bucketname}.s3.amazonaws.com,但是我得到了一个明显的结果 <Cod
https://{bucketname}.s3.amazonaws.com/{FileAndQueryParameters}
我想要的是类似于https://{MyDomainName}/{FileAndQueryParameters}
我已经尝试用我自己的CNAME替换第一个url,指向{bucketname}.s3.amazonaws.com
,但是我得到了一个明显的结果
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your key and signing method.
</Message>
有没有办法做到这一点
顺便说一下,这是我现在使用的代码:
(...)
AmazonS3 client = AWSClientFactory.CreateAmazonS3Client(AccessKey, SecretKey);
string S3_KEY = Key;
string BUCKET_NAME = Bucket;
string FOLDER = SubFolder;
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest();
request.WithBucketName(BUCKET_NAME);
request.WithKey(FOLDER + "/" + S3_KEY);
if (ssUseHTTPS)
{
request.WithProtocol(Protocol.HTTPS);
}
else
{
request.WithProtocol(Protocol.HTTP);
}
if (DownloadFileName != string.Empty)
{
ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides();
responseHeaders.CacheControl = "No-cache";
responseHeaders.ContentDisposition = "attachment; filename=" + DownloadFileName.Replace(";", "").Replace(",", "");
request.ResponseHeaderOverrides = responseHeaders;
}
request.WithExpires(DateTime.Now.AddSeconds(SecondsValidFor));
Url = client.GetPreSignedURL(request);
return Url;
bucket名称必须与域名称相同。花了几天的时间在圈子里试图为预先签名的URL设置自定义CNAME/host,这似乎是不可能的 所有论坛都说这是不可能的,或者你必须重新编码你的整个应用程序来使用cloudfront 将我的DNS从MYBUCKET.s3-WEBSITE-eu-west-1.amazonaws.com更改为MYBUCKET.s3-eu-west-1.amazonaws.com,立即修复了此问题 希望这能帮助别人 工作代码:
function get_objectURL($key) {
// Instantiate the client.
$this->s3 = S3Client::factory(array(
'credentials' => array(
'key' => s3_key,
'secret' => s3_secret,
),
'region' => 'eu-west-1',
'version' => 'latest',
'endpoint' => 'https://example.com',
'bucket_endpoint' => true,
'signature_version' => 'v4'
));
$cmd = $this->s3->getCommand('GetObject', [
'Bucket' => s3_bucket,
'Key' => $key
]);
try {
$request = $this->s3->createPresignedRequest($cmd, '+5 minutes');
// Get the actual presigned-url
$presignedUrl = (string)$request->getUri();
return $presignedUrl;
} catch (S3Exception $e) {
return $e->getMessage() . "\n";
}
}