S3 Ninja+ AWS Java SDK不连接
问题
我想使用S3 Ninja在我自己的网络中模仿S3进行测试和演示目的。我正在使用Java SDK(带有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
The Issue
I want to use S3 Ninja to emulate S3 in my own network for testing and demo purposes. I am using Java SDK (with Scala).
My storage code works fine if it is connected to the real s3 but the same code does not work.
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)
This results in error message logged like this:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根本原因
S3 Java SDK默认为
虚拟托管URL
策略,如果您更改了端点。S3 Ninja需要
路径样式访问
策略。修复程序
可以通过添加
的添加来轻松修改。与客户端构建器的构建呼叫链中的withpathstystyleaccessenabled(true)
。The Root Cause
The S3 Java SDK defaults to
virtual hosted url
strategy if you altered the end-point.S3 Ninja requires the
path style access
strategy.The Fix
This can be easily modified by an addition of
.withPathStyleAccessEnabled(true)
in your client builder's build call chain.