gpt4 book ai didi

java - 在浏览器中打开时,S3 对象 url 不安全(ssl)

转载 作者:行者123 更新时间:2023-12-04 09:33:06 27 4
gpt4 key购买 nike

我正在构建一个小型 REST API 服务来存储和检索照片。为此,我使用 S3 如下:

public String upload(InputStream uploadedInputStream,
Map<String, String> metadata, String group, String filename) {
TransferManager tm = TransferManagerBuilder.standard()
.withS3Client(amazonS3)
.build();
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType(metadata.get(Configuration.CONTENT_TYPE_METADATA_KEY));
// TODO: 26/06/20 Add content-type to metadata
String filepath = group + "/" + filename;
s3transferManager.upload(new PutObjectRequest(
configuration.getProperty("aws.s3.bucket"),
filepath,
uploadedInputStream,
objectMetadata)).waitForUploadResult();
return amazonS3.getUrl(configuration.getProperty("aws.s3.bucket"), filepath).toString();
}
函数返回的

url 看起来像 https://photos.tarkshala.com.s3.ap-south-1.amazonaws.com/default-group/1593911534320%230 .访问时显示如下 enter image description here

当我使用 AWS S3 控制台中提供的对象 url( https://s3.ap-south-1.amazonaws.com/photos.tarkshala.com/default-group/1593911534320%230 ) 打开它时,它显示正常。

enter image description here

为什么 getUrl 方法不返回第二个 url,或者有没有办法获得第二个方法/api?

最佳答案

这是因为 AWS 最近对 s3 进行了更改。

When using virtual hosted–style buckets with SSL, the SSL wild-cardcertificate only matches buckets that do not contain dots ("."). Towork around this, use HTTP or write your own certificate verificationlogic. For more information, see Amazon S3 Path Deprecation Plan.

amazon-s3-path-deprecation-plan-the-rest-of-the-story

创建一个不带点的桶或使用路径样式 URL 或检查 VirtualHostingCustomURLs .

S3支持两种类型的URL访问Object。

  • 虚拟托管方式访问
https://bucket-name.s3.Region.amazonaws.com/key name
  • 路径式请求
https://s3.Region.amazonaws.com/bucket-name/key name

重要

Buckets created after September 30, 2020, will support only virtualhosted-style requests. Path-style requests will continue to besupported for buckets created on or before this date. For moreinformation, see Amazon S3 Path Deprecation Plan – The Rest of theStory.

S3 VirtualHosting

关于java - 在浏览器中打开时,S3 对象 url 不安全(ssl),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62736506/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com