简体   繁体   English

在 google S3 api 上访问存储桶

[英]Accessing a bucket at the google S3 api

I am trying to read a bucket at storage.googleapis.com , using the Amazon Web Services .Net SDK in C#.我正在尝试使用 C# 中的 Amazon Web Services .Net SDK 读取storage.googleapis.com桶。

Can anyone provide a working example of a S3 endpoint Config setup for google, just using the Auth.任何人都可以为 google 提供一个 S3 端点配置设置的工作示例,只需使用 Auth. key/secret pair and a bucket name?密钥/秘密对和存储桶名称? Or using any other method to get this working?或者使用任何其他方法来让它工作?

According to this tutorial this should be a simple matter, but I get all sorts of exceptions when trying to follow the instructions given.根据本教程,这应该是一件简单的事情,但是在尝试按照给出的说明进行操作时,我会遇到各种异常。 Here is an extract of my current attempt - which throws a TrustFailure exception:这是我当前尝试的摘录 - 引发 TrustFailure 异常:

The remote certificate is invalid.远程证书无效。

AmazonS3Config conf = new AmazonS3Config();
// Set regionEndpoint to null, or else the serviceURL will be ignored
conf.RegionEndpoint = null;
conf.ServiceURL = "https://s3.storage.googleapis.com";
conf.UseHttp = false; 
conf.AuthenticationRegion = null;
conf.UseAccelerateEndpoint = false;
conf.UseDualstackEndpoint = false;

AWSCredentials cred = new BasicAWSCredentials("GOOG3LFXXXXXXXXXXXXX", "BQ6VeMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");          
IAmazonS3 client = new AmazonS3Client(cred, conf);

GetBucketVersioningRequest request = new GetBucketVersioningRequest { BucketName = "hisbucket" };
GetBucketVersioningResponse response = client.GetBucketVersioning(request);

You need a Amazon S3 service URL, an access key id, a secret access key id and the bucket name.您需要一个 Amazon S3 服务 URL、一个访问密钥 ID、一个秘密访问密钥 ID 和存储桶名称。

    var s3Config = new AmazonS3Config
    {
        ServiceURL = Constants.AmazonS3ServiceUrl, 
        RegionEndpoint = Amazon.RegionEndpoint.EUWest1
    };

    string accessKeyId = Constants.AmazonAccessKeyId;
    string secretAccessKey = Constants.AmazonSecretAccessKey;

    var config = new AwsS3Config(){AmazonS3BucketName = Constants.AmazonS3BucketName};
    var client = new AmazonS3Client(accessKeyId, secretAccessKey, s3Config);

Then, you should be able to make calls to the amazon client:然后,您应该能够调用亚马逊客户端:

var request = new GetObjectRequest
{
    BucketName = _bucketName,
    Key = entity.Path
};

var response = _client.GetObjectAsync(request).Result;

The code above works on an S3 account, not particularly storage.googleapis.com, which is your case.上面的代码适用于 S3 帐户,而不是特别是 storage.googleapis.com,这是您的情况。 Anyway, I hope this helps and answers your question.无论如何,我希望这会有所帮助并回答您的问题。

I finally got the .NET SDK to upload to Google Cloud Storage with:我终于得到了 .NET SDK 上传到谷歌云存储:

            AWSConfigsS3.UseSignatureVersion4 = false;
            AmazonS3Config config = new AmazonS3Config();
            config.ServiceURL = "https://storage.googleapis.com";
            config.SignatureVersion = "2";
            AmazonS3Client client = new AmazonS3Client(accessKey, secretKey, config);
            var transferUtilityConfig = new TransferUtilityConfig
            {
                ConcurrentServiceRequests = 1,
                MinSizeBeforePartUpload = 6291456000,
            };
            var fileTransferUtilityRequest = new TransferUtilityUploadRequest
            {
                BucketName = bucketName,
                FilePath = filePath,
                PartSize = 6291456000,
                Key = keyName,
            };
            TransferUtility fileTransferUtility = new TransferUtility(client, transferUtilityConfig);
            fileTransferUtility.Upload(fileTransferUtilityRequest);
            fileTransferUtility.Dispose();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM