SecretId
, SecretKey
, and bucket, see Introduction.com.qcloud.cos.*
package.com.qcloud.cos.auth.*
sub-package.com.qcloud.cos.exception.*
sub-package.com.qcloud.cos.model.*
sub-package.com.qcloud.cos.region.*
sub-package.com.qcloud.cos.transfer.*
sub-package.<dependency><groupId>com.qcloud</groupId><artifactId>cos_api</artifactId><version>5.6.133</version></dependency>
com.qcloud.cos.*
. You can import the classes required for running your program through your IDE, such as Eclipse and IntelliJ.// 1. Initialize the user credentials (secretId, secretKey).String secretId = "COS_SECRETID";String secretKey = "COS_SECRETKEY";COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);// 2. Set the bucket region. For abbreviations of COS regions, see https://www.tencentcloud.com/document/product/436/6224// `clientConfig` contains the set methods to set region, HTTPS (HTTP by default), timeout, and proxy. For detailed usage, see the source code or the FAQs about the SDK for Java.Region region = new Region("COS_REGION");ClientConfig clientConfig = new ClientConfig(region);// 3. Generate a COS client.COSClient cosClient = new COSClient(cred, clientConfig);
// 1. Pass in the obtained temporary key (tmpSecretId, tmpSecretKey, sessionToken).String tmpSecretId = "COS_SECRETID";String tmpSecretKey = "COS_SECRETKEY";String sessionToken = "COS_TOKEN";BasicSessionCredentials cred = new BasicSessionCredentials(tmpSecretId, tmpSecretKey, sessionToken);// 2. Set the bucket region. For abbreviations of COS regions, see https://www.tencentcloud.com/document/product/436/6224// `clientConfig` contains the set methods to set region, HTTPS (HTTP by default), timeout, and proxy. For detailed usage, please see the source code or the FAQs about the SDK for Java.Region region = new Region("COS_REGION");ClientConfig clientConfig = new ClientConfig(region);// 3. Generate a COS clientCOSClient cosClient = new COSClient(cred, clientConfig);
Member Name | Setting Method | Description | Type |
region | Constructor or set method | Region | |
httpProtocol | Set method | The protocol used by the request. By default, HTTP is used to interact with COS. | HttpProtocol |
signExpired | Set method | Validity period (in seconds) of the request signature. Default value: 3600 . | int |
connectionTimeout | Set method | Timeout period in milliseconds for connection with COS. Default value: 30000 . | int |
socketTimeout | Set method | Timeout period in milliseconds for the client to read data. Default value: 30000 . | int |
httpProxyIp | Set method | Proxy server IP | String |
httpProxyPort | Set method | Proxy server port | int |
//1. Create a template request objectMediaBucketRequest request = new MediaBucketRequest();//2. Add request parameters as detailed in the API documentationrequest.setBucketName("examplebucket-1250000000");//3. Call the API to get the bucket response objectMediaBucketResponse response = client.describeMediaBuckets(request);
//1. Create a job request objectMediaJobsRequest request = new MediaJobsRequest();//2. Add request parameters as detailed in the API documentationrequest.setBucketName("examplebucket-1250000000");request.setTag("Transcode");request.getInput().setObject("1.mp4");request.getOperation().setTemplateId("t0e09a9456d4124542b1f0e44d501*****");request.getOperation().getOutput().setBucket("examplebucket-1250000000");request.getOperation().getOutput().setRegion("ap-chongqing");request.getOperation().getOutput().setObject("2.mp4");request.setQueueId("p9900025e4ec44b5e8225e70a521*****");//3. Call the API to get the job response objectMediaJobResponse response = client.createMediaJobs(request);
MediaJobsRequest request = new MediaJobsRequest();request.setBucketName("examplebucket-1250000000");request.setJobId("jae776cb4ec3011eab2cdd3817d4*****");Boolean response = client.cancelMediaJob(request);
//1. Create a job request objectMediaJobsRequest request = new MediaJobsRequest();//2. Add request parameters as detailed in the API documentationrequest.setBucketName("examplebucket-1250000000");request.setJobId("j29a82fea08ba11ebb54bc9d1c05*****");//3. Call the API to get the job response objectMediaJobResponse response = client.describeMediaJob(request);
MediaJobsRequest request = new MediaJobsRequest();request.setBucketName("examplebucket-1250000000");request.setQueueId("p9900025e4ec44b5e8225e70a521*****");request.setTag("Transcode");MediaListJobResponse response = client.describeMediaJobs(request);List<MediaJobObject> jobsDetail = response.getJobsDetail();
// Close the client (release server threads).cosClient.shutdown();
Was this page helpful?