Reputation: 155
Does anyone konw how to add custom endpoint using s3 net API??
Detail:https://github.com/aws/aws-sdk-net/issues/1283
code Language:C#
the sServiceUrl value="192.168.199.216:7480"
when i call DoesS3BucketExist function,i reviced a Exception(System.UriFormatException)
This is my code
public IAmazonS3 CreateClient(string sAccessKeyId, string sAccessKeySecret, string sServiceUrl)
{
AmazonS3Client s3Client = null;
try
{
AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = sServiceUrl;
config.UseHttp = false;
config.SignatureVersion = "v4";
AWSConfigsS3.UseSignatureVersion4 = true;
s3Client = new AmazonS3Client(
sAccessKeyId,
sAccessKeySecret,
config
);
}
catch (Exception ex)
{
LogHelper.WriteLog("AWS配置", ex, "创建AmazonS3Client失败!");
}
return s3Client;
}
public bool DoesBucketExist(string bucketName)
{
bool bIsExist;
if (this.Client != null)
{
bIsExist = this.Client.DoesS3BucketExist(bucketName);
}
else
{
bIsExist = false;
}
return bIsExist;
}
i want to set this property AWSConfigs.EndpointDefinition = @"c:pathtoendpoints.xml";
,but i don't know how to custom endpoints.json file.
it's so hard to me,maybe i need a god help me!Any Help will appreciated!
Upvotes: 5
Views: 6285
Reputation: 155
static void Main(string[] args)
{
string accessKey = "";
string secretKey = "";
AmazonS3Config config = new AmazonS3Config()
{
ServiceURL = string.Format("http://{0}", "192.168.199.216:7480"),
UseHttp = true,
ForcePathStyle = true,
ProxyHost = "192.168.199.216",
ProxyPort = 7480
};
AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3Client s3Client = new AmazonS3Client(creds, config);
ListBucketsResponse response = s3Client.ListBuckets();
foreach (S3Bucket b in response.Buckets)
{
Console.WriteLine("{0}\t{1}", b.BucketName, b.CreationDate);
}
}
Upvotes: 7