public URL getObjectUrl(String bucketName, String key);
// Identity information does not need to be verified.COSCredentials cred = new AnonymousCOSCredentials();// `ClientConfig` contains the COS client configuration for subsequent COS requests.ClientConfig clientConfig = new ClientConfig();// Set the bucket region.// For more information on COS regions, please visit https://www.tencentcloud.com/document/product/436/6224.clientConfig.setRegion(new Region("COS_REGION"));// Set the URL generation request protocol, `http` or `https`.// For 5.6.53 and earlier versions, HTTPS is recommended.// Starting from 5.6.54, HTTPS is used by default.clientConfig.setHttpProtocol(HttpProtocol.https);// Generate the COS client.COSClient cosclient = new COSClient(cred, clientConfig);// Enter the bucket name in the format of `BucketName-APPID`.String bucketName = "examplebucket-1250000000";// Object key, the unique ID of an object in a bucket. For more information, please see [Object Key](https://www.tencentcloud.com/document/product/436/13324).String key = "exampleobject";System.out.println(cosclient.getObjectUrl(bucketName, key));
Parameter | Description | Type | Required |
Bucket | Bucket name in the format of BucketName-APPID | String | Yes |
Key | Object key, the unique ID of an object in a bucket. For more information, please see Object Key | String | Yes |
Was this page helpful?