S3 Ninja+ AWS Java SDK不连接

发布于 2025-01-21 18:54:13 字数 1155 浏览 1 评论 0原文

问题

我想使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒路情人 2025-01-28 18:54:13

根本原因

S3 Java SDK默认为虚拟托管URL策略,如果您更改了端点。
S3 Ninja需要路径样式访问策略。

修复程序

可以通过添加的添加来轻松修改。与客户端构建器的构建呼叫链中的withpathstystyleaccessenabled(true)

  val client = AmazonS3ClientBuilder.standard()
    .withCredentials(credentialProvider)
    .withEndpointConfiguration(ep)
    .withPathStyleAccessEnabled(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.

  val client = AmazonS3ClientBuilder.standard()
    .withCredentials(credentialProvider)
    .withEndpointConfiguration(ep)
    .withPathStyleAccessEnabled(true)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文