SecretID and SecretKey from the CAM console.Endpoint. Suppose the bucket region is ap-guangzhou:AmazonS3Client s3 = new AmazonS3Client(new AWSCredentialsProvider() {@Overridepublic AWSCredentials getCredentials() {// Here, the backend requests for a temporary key from STS.return new BasicSessionCredentials("<TempSecretID>", "<TempSecretKey>", "<STSSessionToken>");}@Overridepublic void refresh() {//}});s3.setEndpoint("cos.ap-guangzhou.myqcloud.com");
-(AWSTask<AWSCredentials *> *)credentials{// Here, the backend requests for a temporary key from STS.AWSCredentials *credential = [[AWSCredentials alloc]initWithAccessKey:@"<TempSecretID>" secretKey:@"<TempSecretKey>" sessionKey:@"<STSSessionToken>" expiration:[NSDate dateWithTimeIntervalSince1970:1565770577]];return [AWSTask taskWithResult:credential];}- (void)invalidateCachedTemporaryCredentials{}
ap-guangzhou:NSURL* bucketURL = [NSURL URLWithString:@"https://cos.ap-guangzhou.myqcloud.com"];AWSEndpoint* endpoint = [[AWSEndpoint alloc] initWithRegion:AWSRegionUnknown service:AWSServiceS3 URL:bucketURL];AWSServiceConfiguration* configuration = [[AWSServiceConfiguration alloc]initWithRegion:AWSRegionUSEast2 endpoint:endpointcredentialsProvider:[MyCredentialProvider new]]; // `MyCredentialProvider` implements the `AWSCredentialsProvider` protocol.[[AWSServiceManager defaultServiceManager] setDefaultServiceConfiguration:configuration];
Endpoint. Supposing the bucket region is ap-guangzhou, the sample code is as follows:var AWS = require('aws-sdk');AWS.config.update({accessKeyId: "COS_SECRETID",secretAccessKey: "COS_SECRETKEY",region: "ap-guangzhou",endpoint: 'https://cos.ap-guangzhou.myqcloud.com',});s3 = new AWS.S3({apiVersion: '2006-03-01'});
~/.aws/config):[default]s3 =addressing_style = virtual
~/.aws/credentials): [default]aws_access_key_id = [COS_SECRETID]aws_secret_access_key = [COS_SECRETKEY]
ap-guangzhou, the sample code is as follows:AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://cos.ap-guangzhou.myqcloud.com","ap-guangzhou")).build();
S3Client s3Client = S3Client.builder().endpointOverride(URI.create("http://cos.ap-guangzhou.myqcloud.com")).region(Region.of("ap-guangzhou")).build();
~/.aws/config):[default]s3 =signature_version = s3addressing_style = virtual
~/.aws/credentials): [default]aws_access_key_id = [COS_SECRETID]aws_secret_access_key = [COS_SECRETKEY]
Endpoint in the codeap-guangzhou:client = boto3.client('s3', endpoint_url='https://cos.ap-guangzhou.myqcloud.com')
~/.aws/config):[default]s3 =addressing_style = virtual
~/.aws/credentials): [default]aws_access_key_id = [COS_SECRETID]aws_secret_access_key = [COS_SECRETKEY]
Endpoint in the codeap-guangzhou:$S3Client = new S3Client(['region' => 'ap-guangzhou','version' => '2006-03-01','endpoint' => 'https://cos.ap-guangzhou.myqcloud.com']);
Endpoint. Supposing the bucket region is ap-guangzhou, the sample code is as follows:string sAccessKeyId = "COS_SECRETID";string sAccessKeySecret = "COS_SECRETKEY";string region = "ap-guangzhou";var config = new AmazonS3Config() { ServiceURL = "https://cos." + region + ".myqcloud.com" };var client = new AmazonS3Client(sAccessKeyId, sAccessKeySecret, config);
ap-guangzhou:func newSession() (*session.Session, error) {creds := credentials.NewStaticCredentials("COS_SECRETID", "COS_SECRETKEY", "")region := "ap-guangzhou"endpoint := "http://cos.ap-guangzhou.myqcloud.com"config := &aws.Config{Region: aws.String(region),Endpoint: &endpoint,S3ForcePathStyle: aws.Bool(true),Credentials: creds,// DisableSSL: &disableSSL,}return session.NewSession(config)}
sess, _ := newSession()service := s3.New(sess)// Take file upload as an example.fp, _ := os.Open("yourLocalFilePath")defer fp.Close()ctx, cancel := context.WithTimeout(context.Background(), time.Duration(30)*time.Second)defer cancel()service.PutObjectWithContext(ctx, &s3.PutObjectInput{Bucket: aws.String("examplebucket-1250000000"),Key: aws.String("exampleobject"),Body: fp,})
package mainimport ("context""fmt""github.com/aws/aws-sdk-go-v2/aws""github.com/aws/aws-sdk-go-v2/config""github.com/aws/aws-sdk-go-v2/credentials""github.com/aws/aws-sdk-go-v2/service/s3""os""strings")func main() {// Get the key through environment variables SECRETID and SECRETKEYcreds := credentials.NewStaticCredentialsProvider(os.Getenv("SECRETID"), os.Getenv("SECRETKEY"), "") // KeycustomResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {return aws.Endpoint{PartitionID: "aws",URL: "http://cos.ap-guangzhou.myqcloud.com",SigningRegion: "ap-guangzhou",}, nil})cfg, _ := config.LoadDefaultConfig(context.TODO(),config.WithCredentialsProvider(creds),config.WithEndpointResolverWithOptions(customResolver))s3Client := s3.NewFromConfig(cfg, func(o *s3.Options) {o.UsePathStyle = false // Access using virtual-host style})input := &s3.PutObjectInput{Body: strings.NewReader("xxxxxxx"),Bucket: aws.String("test-1250000000"), //Bucket nameKey: aws.String("test"), //Object keyStorageClass: "STANDARD",}result, err := s3Client.PutObject(context.Background(), input)if err != nil {panic(err)}fmt.Println(result)
~/.aws/config):[default]s3 =addressing_style = virtual
~/.aws/credentials): [default]aws_access_key_id = [COS_SECRETID]aws_secret_access_key = [COS_SECRETKEY]
ap-guangzhou, the sample code is as follows:Aws::Client::ClientConfiguration awsCC;awsCC.scheme = Aws::Http::Scheme::HTTP;awsCC.region = "ap-guangzhou";awsCC.endpointOverride = "cos.ap-guangzhou.myqcloud.com";Aws::S3::S3Client s3_client(awsCC);
Feedback