com.branch.cos.demo.CAMRoleDemo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of branch_cos_api Show documentation
Show all versions of branch_cos_api Show documentation
branch java sdk for qcloud cos
package com.branch.cos.demo;
import com.branch.cos.COSClient;
import com.branch.cos.ClientConfig;
import com.branch.cos.auth.*;
import com.branch.cos.model.PutObjectRequest;
import com.branch.cos.model.PutObjectResult;
import com.branch.cos.model.StorageClass;
import com.branch.cos.region.Region;
import java.io.File;
public class CAMRoleDemo {
public static void SimpleUploadFileFromLocal() {
InstanceMetadataCredentialsEndpointProvider endpointProvider =
new InstanceMetadataCredentialsEndpointProvider(InstanceMetadataCredentialsEndpointProvider.Instance.CVM);
InstanceCredentialsFetcher instanceCredentialsFetcher = new InstanceCredentialsFetcher(endpointProvider);
COSCredentialsProvider cosCredentialsProvider = new InstanceCredentialsProvider(instanceCredentialsFetcher);
ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
COSClient cosClient = new COSClient(cosCredentialsProvider,clientConfig);
String bucketName = "3399demo-125xxxxxxxx";
String key = "test/demo.txt";
File localFile = new File("test");
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
putObjectRequest.setStorageClass(StorageClass.Standard);
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
cosClient.shutdown();
}
public static void main(String[] args) {
SimpleUploadFileFromLocal();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy