简体   繁体   English

AWS S3 POST 策略内容长度范围不适用于精确的文件大小匹配

[英]AWS S3 POST Policy content-length-range doesn't work for exact file size match

I'd like to add file size validation to our signed urls, making sure the client uploads a file of exactly the size I signed it with.我想为我们签名的 url 添加文件大小验证,确保客户端上传的文件大小与我签名的大小完全一致 However, when I do this:但是,当我这样做时:

"conditions": [
    {"acl": "public-read"},
    .... ,
    ["content-length-range", 1024, 1024]
]

For small files, it works.对于小文件,它有效。
But a bit larger files, for example 25mb, it results in EntityTooSmall error.但是稍大的文件,例如 25mb,会导致EntityTooSmall错误。

It starts working only if I set the minimum to 0 like this:只有当我像这样将最小值设置为 0 时它才会开始工作:

["content-length-range", 0, 1024]

But I want to enforce a specific file size, and not a range.但我想强制执行特定的文件大小,而不是范围。
Does S3 not support exact file size match? S3 不支持精确的文件大小匹配吗?

Unfortunately, no.很不幸的是,不行。 You can specify only a range.您只能指定一个范围。 I would check if the file size limit is specified correctly.我会检查是否正确指定了文件大小限制。 This error likely indicates that the calculation wasn't right.此错误可能表明计算不正确。

To test it further, I'd suggest generating a file with the exact size using eg dd tool, like this为了进一步测试它,我建议使用 eg dd 工具生成一个具有确切大小的文件,如下所示

dd if=/dev/zero of=test-file-1 bs=26214400 count=1

Then try to upload it.然后尝试上传它。 In this case, your range must be [26214400,26214400].在这种情况下,您的范围必须是 [26214400,26214400]。

I managed to test with Postman an exact file size and everything is working correctly.我设法用 Postman 测试了一个确切的文件大小,一切正常。 The condition that I used is:我使用的条件是:

const Conditions = [
    ["content-length-range", 30789588, 30789588],
    ["eq", "$Content-Type", "image/jpeg"]
];

I downloaded the 30MB file from here: https://sample-videos.com/download-sample-jpg-image.php我从这里下载了 30MB 的文件: https://sample-videos.com/download-sample-jpg-image.php

When I change the size of the content length to 30789587 I get the following:当我将内容长度的大小更改为 30789587 时,我得到以下信息:

<Error>
    <Code>EntityTooLarge</Code>
    <Message>Your proposed upload exceeds the maximum allowed size</Message>
    <ProposedSize>30789588</ProposedSize>
    <MaxSizeAllowed>30789587</MaxSizeAllowed>
</Error> 

And with a content length of 30789589:内容长度为 30789589:

<Error>
    <Code>EntityTooSmall</Code>
    <Message>Your proposed upload is smaller than the minimum allowed size</Message>
    <ProposedSize>30789588</ProposedSize>
    <MinSizeAllowed>30789589</MinSizeAllowed>
</Error> 

Test with the same file I used and let's see if it works for you.使用我使用的相同文件进行测试,让我们看看它是否适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM