SignatureDoesNotMatch将mp3 / m4a文件上传到S3但上传所有其他文件时出错

时间:2017-08-23 20:01:16

标签: django reactjs file-upload amazon-s3

我正在使用react-s3-uploader将文件上传到S3存储桶。所有文件类型和文件大小都可以执行mp3和m4a文件。大型mp4文件上传没有问题,图像,文本等。我​​甚至将mp3的文件扩展名更改为mp4并上传。但是,每次我尝试上传mp4或m4a S3时都会返回 SignatureDoesNotMatch 错误:

<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<AWSAccessKeyId>******</AWSAccessKeyId>
<StringToSign>PUT

audio/mp3
1503508664
x-amz-acl:private
/tl2/generic_video/4/1-05IGuessHedRatherBeInColorado.mp3</StringToSign>
<SignatureProvided>dt1lf51Z/L/4pvkj3dC9ybOTTRw=</SignatureProvided>
<StringToSignBytes>50 55 54 0a 0a 61 75 64 69 6f 2f 6d 70 33 0a 31 35 30 33 35 30 38 36 36 34 0a 78 2d 61 6d 7a 2d 61 63 6c 3a 70 72 69 76 61 74 65 0a 2f 74 6c 32 2f 67 65 6e 65 72 69 63 5f 76 69 64 65 6f 2f 34 2f 31 2d 30 35 49 47 75 65 73 73 48 65 64 52 61 74 68 65 72 42 65 49 6e 43 6f 6c 6f 72 61 64 6f 2e 6d 70 33</StringToSignBytes>
<RequestId>FDA3BA86E19BEA87</RequestId>
<HostId>***</HostId>
</Error>

以下是客户端和服务器的代码段。

JS react-s3-uploader代码段:

onDrop(acceptedFiles,rejectedFiles){
    var s3u = new S3Upload({
      files: acceptedFiles,
      signingUrl:this.uploadOptions.signingUrl,
      uploadRequestHeaders: { 'x-amz-acl': 'private' },
      onProgress:this.handleUploadProgress.bind(this),
      onError:this.handleUploadError.bind(this),
      onFinishS3Put:this.handleFinishedUpload.bind(this),
    });
    this.setState({files:acceptedFiles});
  }

Django终止获取签名的网址摘要:

import boto
conn = boto.connect_s3(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
        object_name = request.GET['objectName']
        key_name = ('generic_video/' +str(ru.customer.pk)+'/'+ object_name).encode('utf-8')
        content_type = mimetypes.guess_type(object_name)[0]
        signed_url = conn.generate_url(
            300,
            "PUT",
            settings.AWS_EXPECTED_BUCKET,
            key_name,
            headers = {'Content-Type': content_type, 'x-amz-acl':'private'})

        return HttpResponse(json.dumps({'signedUrl': signed_url}))

请求标题:

Request Method:PUT
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:1036324
Content-Type:audio/mp3
Origin:http://localhost:8000
Pragma:no-cache
Referer:http://localhost:8000/c/uploads/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36
x-amz-acl:private

响应标题:

Status Code:403 Forbidden
Access-Control-Allow-Credentials:true
Access-Control-Allow-Methods:PUT, POST
Access-Control-Allow-Origin:http://localhost:8000
Access-Control-Expose-Headers:ETag
Access-Control-Max-Age:3000
Connection:close
Content-Type:application/xml
Date:Wed, 23 Aug 2017 18:51:14 GMT
Server:AmazonS3
Transfer-Encoding:chunked
Vary:Origin, Access-Control-Request-Headers, Access-Control-Request-Method
x-amz-id-2:*****
x-amz-request-id:1DCF27CCB82C1FF0

上传mp3有什么特别的技巧吗?我觉得我错过了一些简单的东西?

0 个答案:

没有答案