Apache Ozone + AWS S3 .Net API:PutObject正在创建存储桶而不是密钥 [英] Apache Ozone + AWS S3 .Net API: PutObject is creating a bucket instead of a key

查看:267
本文介绍了Apache Ozone + AWS S3 .Net API:PutObject正在创建存储桶而不是密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用适用于.NET的AWS S3 API在apache OZone中创建密钥.

I am trying to create keys in apache OZone using AWS S3 API for .NET.

我要创建的密钥必须位于我使用AWS S3 CLI创建的名为"test"的存储桶中.

The key I am trying to create must be inside a bucket called "test" that I created using AWS S3 CLI.

我的代码:

    static async Task WriteFile()
    {
        AmazonS3Config config = new AmazonS3Config();
        config.ServiceURL = "http://myApacheOzoneEndpoint:8744"; // This port is mapped from a docker container to (not the original endpoint port for Ozone)

        AWSCredentials credentials = new BasicAWSCredentials("testuser/scm@EXAMPLE.COM", "c261b6ecabf7d37d5f9ded654b1c724adac9bd9f13e247a235e567e8296d2999"); // Credentials must be set but can be random since Ozone doesn't use authentication
        AmazonS3Client client = new AmazonS3Client(credentials, config);

        using (FileStream fs = File.OpenRead(@"C:\Users\me\path.to.file\image.jpg"))
        {
            string responseBody = "";
            try
            {
                PutObjectRequest request = new PutObjectRequest
                {

                    BucketName = "test",
                    Key = "deleteme.jpg",
                    InputStream = fs
                };

                PutObjectResponse response = await client.PutObjectAsync(request);
                Console.WriteLine($"Result: {response.HttpStatusCode.ToString()}");
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine("Error encountered ***. Message:'{0}' when writing an object", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
            }
        }
    }

此代码返回200代码错误(确定),如果我从API调用GetObjectAsync,我将得到一个带有元数据的HTML(但目前无法读取文件内容)

This code is returning a 200 code error (OK), and if I call GetObjectAsync from the API I get an HTML with metadata as result (But can't read the file content by the moment)

然后我去Apache Ozone并在臭氧外壳内执行以下命令:

Then I go to Apache Ozone and execute these commands in within the ozone shell:

bash-4.2$ ozone s3  path test
Volume name for S3Bucket is : s3c89e813c80ffcea9543004d57b2a1239
Ozone FileSystem Uri is : o3fs://test.s3c89e813c80ffcea9543004d57b2a1239
bash-4.2$ ozone sh bucket list /s3c89e813c80ffcea9543004d57b2a1239
[ {
  "volumeName" : "s3c89e813c80ffcea9543004d57b2a1239",
  "bucketName" : "test",
  "createdOn" : "Wed, 01 Apr 2020 08:06:40 GMT",
  "acls" : null,
  "versioning" : "DISABLED",
  "storageType" : "DISK",
  "encryptionKeyName" : "N/A"
}, {
  "volumeName" : "s3c89e813c80ffcea9543004d57b2a1239",
  "bucketName" : "deleteme.jpg",
  "createdOn" : "Tue, 31 Mar 2020 10:57:26 GMT",
  "acls" : null,
  "versioning" : "DISABLED",
  "storageType" : "DISK",
  "encryptionKeyName" : "N/A"
} ]
bash-4.2$ ozone sh key list /s3c89e813c80ffcea9543004d57b2a1239/test => This command returns only keys that have been put from AWS S3 CLI

如您所见,该对象在用于S3的Ozone体积内创建为新存储桶,而不是在test存储桶下创建为新键.如果我尝试放置来自AWS S3 Cli的密钥,它将按预期工作

As you can see, the object is created as a new bucket inside the Ozone volume used for S3, instead of being created as a new key below testbucket. If I try to put keys from AWS S3 Cli it works as expected

发生了什么事?

仅供参考,我从Java API制作了相同的示例,并且发生了相同的问题!

FYI I made the same example from Java API and the same issue occurs!

谢谢

推荐答案

臭氧s3-gateway默认使用

Ozone s3-gateway uses by default the path-style addressing while updated sdk libraries use the virtual-hosted addressing. The quickest solution would be to switch to path-style:

// AmazonS3Config config = new AmazonS3Config();
config.ForcePathStyle = true;

或者,如文档中所述,您可以在臭氧中启用虚拟主机架构.

Alternatively, as mentioned on the docs, you could enable the virtual-hosted schema in ozone.

请注意,路径样式 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆