Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 need to implement policy to limit file size #1426

Closed
gao2009ss opened this issue Aug 19, 2020 · 2 comments
Closed

S3 need to implement policy to limit file size #1426

gao2009ss opened this issue Aug 19, 2020 · 2 comments

Comments

@gao2009ss
Copy link

版本1.90

问题一:

例如正确地址
http://127.0.0.1:8333/testbucket/file/topic/2020-08-19/image/93380c2d1739420d88ad743ed9ed02c0a16d44128a84c4e56b67cc8bf77d07bbc.jpg

使用listObjectsV2查询返回地址

http://127.0.0.1:8333/testbucket/file/topic/2020-08-19/image93380c2d1739420d88ad743ed9ed02c0a16d44128a84c4e56b67cc8bf77d07bbc.jpg

对比发现在文件名前面少了一个斜杆

查询代码:

`S3Client s3Client = ...

ListObjectsV2Request listObjectsReqManual = ListObjectsV2Request.builder()
.bucket("testbucket")
.maxKeys(6)
.prefix("file/topic/")
.build();

boolean done = false;
while (!done) {
ListObjectsV2Response listObjResponse = s3Client.listObjectsV2(listObjectsReqManual);
for (S3Object content : listObjResponse.contents()) {
System.out.println(content.key());
}

		if (listObjResponse.nextContinuationToken() == null) {
		    done = true;
		}
		System.out.println("分页");
		listObjectsReqManual = listObjectsReqManual.toBuilder()
		       .continuationToken(listObjResponse.nextContinuationToken())
		       .build();

}`

问题二:建议S3接口实现Policy功能
使用S3接口就是需要它的预签名功能,Policy里的content-length-range属性可以限制上传文件大小,这样在客户端使用预签名URL直传就不会让文件上传大小超出限制

参照API
https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html
https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/dev/HTTPPOSTExamples.html
https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html

@chrislusf chrislusf reopened this Aug 19, 2020
@chrislusf
Copy link
Collaborator

fixed the first one

@chrislusf chrislusf changed the title S3网关listObjectsV2查询结果少一个斜杆 S3 need to implement policy for TTL Aug 31, 2020
@chrislusf chrislusf changed the title S3 need to implement policy for TTL S3 need to implement policy to limit file size Sep 19, 2020
@chrislusf
Copy link
Collaborator

Implemented PostPolicy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants