dongshenghe1833 2019-03-16 04:12
浏览 172

使用为S3构建的预签名URL将S3 PutObject到CloudFront会导致错误

In my server, I build a presigned S3 URL like this:

// Initialize a session in us-east-1 that the SDK will use to load
// credentials from the shared credentials file ~/.aws/credentials.
sess, err := session.NewSession(&aws.Config{
    Region: aws.String("us-east-1")},
)
if err != nil {
    // ...
}

// Create S3 service client.
svc := s3.New(sess)

// Create the S3 PutObject request.
resp, _ := svc.PutObjectRequest(&s3.PutObjectInput{
    Bucket: aws.String("REDACTED"),
    Key:    aws.String(key),
})

// Pre-sign the request to get a URL.
url, err := resp.Presign(20 * time.Second)
if err != nil {
    // ...
}

In the browser, I make a PutObject call to S3 using the presigned URL, like this (notice that I change the REDACTED.s3.amazonaws.com URL to https://cdn.REDACTED.com, which is my CloudFront endpoint:

http.get(`/get-presigned-url`).subscribe(
    (url: string) =>  {
        const s3Url = 'https://REDACTED.s3.amazonaws.com/';
        const cloudfrontUrl = 'https://cdn.REDACTED.com/';
        http.put(url.replace(s3Url, cloudfrontUrl), file).subscribe(...);
    }
);

The browser gives me this error in return, a 400 Bad Request:

" InvalidArgumentOnly one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specifiedAuthorizationAWS REDACTED=REDACTED+REDACTED/REDACTED="

Any ideas what's up?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大