The Issue
为了测试和演示目的,我想使用S3忍者在我自己的网络中模拟S3。我正在使用Java (与Scala一起)。
如果我的存储代码连接到实际的s3,那么它可以正常工作,但是相同的代码不能工作。
override def store(bucketName: String, keyName: String, source: File):
BlobStoreResult = {
val iAm = "store"
val transferManager = TransferManagerBuilder.standard
.withS3Client(createS3Client())
.build
val fileName = source.toPath.getFileName.toString
try {
val transfer = transferManager.upload(bucketName, keyName, source)这将导致记录如下的错误消息:
c.a.request - Sending Request: PUT http://test-bucket.localhost:9444 /png-test.png
Headers: (amz-sdk-invocation-id: bb866d5c-2ac7-4b30-579b-01df10b96e81, Content-Length:
924, Content-MD5: Trqia4kjznKAi0p/v3JesA==, Content-Type: image/png, User-Agent: aws-
sdk-java/1.12.53 Windows_10/10.0 Eclipse_OpenJ9_VM/openj9-0.27.0 java/11.0.12
scala/2.13.6 groovy/2.5.14 vendor/International_Business_Machines_Corporation
cfg/retry-mode/legacy com.amazonaws.services.s3.transfer.TransferManager/1.12.53, )
c.a.a.AWS4Signer - AWS4 Canonical Request: '"PUT
/png-test.png发布于 2022-04-15 19:29:52
的根本原因
如果更改了终结点,S3 Java默认为virtual hosted url策略。S3忍者需要path style access策略。
The Fix
通过在客户端构建器的构建调用链中添加.withPathStyleAccessEnabled(true),可以轻松地对此进行修改。
val client = AmazonS3ClientBuilder.standard()
.withCredentials(credentialProvider)
.withEndpointConfiguration(ep)
.withPathStyleAccessEnabled(true)https://stackoverflow.com/questions/71888151
复制相似问题