代码之家  ›  专栏  ›  技术社区  ›  Lansana Camara

S3使用为S3构建的预先指定的URL将object放入CloudFront会导致错误

  •  0
  • Lansana Camara  · 技术社区  · 7 年前

    // 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 {
        // ...
    }
    

    在浏览器中,我创建一个 PutObject 使用预先指定的URL调用S3,如下所示(注意,我更改了 REDACTED.s3.amazonaws.com 指向的URL https://cdn.REDACTED.com

    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(...);
        }
    );
    

    浏览器返回这个错误,400个错误请求:

    InvalidArgument 查询字符串参数或授权标头应为 指定授权AWS 修订=修订+修订/修订=“

    0 回复  |  直到 7 年前