0

对于小文件(小于 5MB),Fineuploader 发送一个完整的策略对象进行签名,并且上传成功,包括向客户端发送临时链接的后处理,以及一些服务器端管理的东西。我使用服务器的官方FineUploader S3 演示 PHP 代码。https://github.com/Widen/fine-uploader-server/blob/master/php/s3/s3demo-thumbnails.php

签名请求示例(格式化、匿名):

{
    "expiration": "2013-12-28T12:57:42.354Z",
    "conditions": [
        {"acl": "private"},
        {"bucket": "TOP-SECRET-BUCKET-NAME"},
        {"Content-Type": "application/pdf"},
        {"success_action_status": "200"},
        {"key": "bfccb67e-5343-4e01-97ff-2dcffe681da0.pdf"},
        {"x-amz-meta-qqfilename": "plakat_a3.pdf"},
        ["content-length-range","0","1000111000111"]
    ]
}

响应包含策略和签名(格式化):

{
    "policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0xMi0yOFQxMzoxODoyNy4yODhaIiwiY29uZGl0aW9ucyI6W3siYWNsIjoicHJpdmF0ZSJ9LHsiYnVja2V0IjoiZGVtb2Nza2EifSx7IkNvbnRlbnQtVHlwZSI6ImFwcGxpY2F0aW9uXC9wZGYifSx7InN1Y2Nlc3NfYWN0aW9uX3N0YXR1cyI6IjIwMCJ9LHsia2V5IjoiMWZiMjZmMjAtNjg2Ni00YjU1LTg3YTctZWZlMjNiOWMwZmY1LnBkZiJ9LHsieC1hbXotbWV0YS1xcWZpbGVuYW1lIjoicGxha2F0X2EzLnBkZiJ9LFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLCIwIiwiMTAwMDExMTAwMDExMSJdXX0=",
    "signature":"Wlw1QJjwmsASyQemUWrYuktiQwE="
}

...但对于较大的文件 Fineupload 发送不同的签名请求,其中仅包含标头(格式化,匿名):

{
    "headers": "POST\n\nvideo/quicktime\n\nx-amz-acl:private\nx-amz-date:Sat, 28 Dec 2013 12:53:13 GMT\nx-amz-meta-qqfilename:20MB_stopmot-minta.mov\n/TOP_SECRET-BUCKET-NAME/d2033a4c-1e55-49a0-8589-9b1725dcd013.mov?uploads"
}

响应仅包含签名(格式化):

{
    "signature":"jYtFC91wIPkZj31W\/vwuK9ClawU="
}

在这种情况下,OPTIONS对 amazon S3 的请求失败:

Request Headers 14:09:09.000
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
Pragma: no-cache
Origin: http://top-secret.example.com
Host: TOP-SECRET-BUCKET-NAME.s3.amazonaws.com
Connection: keep-alive
Cache-Control: no-cache
Access-Control-Request-Method: POST
Access-Control-Request-Headers: authorization,content-type,x-amz-acl,x-amz-date,x-amz-meta-qqfilename
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

回复:

  • 状态:403
  • 身体:

响应标头:

x-amz-request-id: 625913F399C626A2
x-amz-id-2: +enheIuZT0RJ+11THF1TuNsA6bCqE4a2ppsklK84k4KXdNX4UsuGhxPf00Eb137G
Transfer-Encoding: chunked
Server: AmazonS3
Date: Sat, 28 Dec 2013 13:18:01 GMT
Content-Type: application/xml

测试用例:

  • 使用较小.mov的 , .mp3, .pdf,.log文件进行测试:课程 #1(成功)
  • 使用较大的文件(相同类型)进行测试:课程 #2(失败)

什么会导致差异?我该如何/应该修复它?

4

1 回答 1

4

我需要<ExposeHeader>ETag</ExposeHeader>在 Amazon S3 存储桶权限中添加到我的 CORS 配置。所以最后它看起来类似于:

<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <ExposeHeader>ETag</ExposeHeader>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

参考:

http://docs.fineuploader.com/endpoint_handlers/amazon-s3.html

于 2013-12-28T15:47:24.257 回答