java.lang.NoSuchMethodError is reported when I run the SDK?NoSuchMethodError.
Solution:NoSuchMethodError to the version of the corresponding library in pom.xml in the SDK.cos-java-sdk with cos_api-bundle. In this case, all dependencies of cos-java-sdk are installed independently, so more space will be used.<groupId>com.qcloud</groupId><artifactId>cos_api-bundle</artifactId><version>5.6.35</version>
SetConnectionTimeoutMs and setSocketTimeout methods in the SDK to adjust them respectively.IOException is frequently printed in the log?IOException is printed in WARN logs, it can be ignored, and the SDK will retry. IOException may be caused by a slow network connection. For solutions, see steps 1 and 2 above.<groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.3</version>
cos-java-sdk with cos_api-bundle. In this case, all dependencies of cos-java-sdk are installed independently, so more space will be used.<groupId>com.qcloud</groupId><artifactId>cos_api-bundle</artifactId><version>5.6.35</version>
cos-java-sdk with cos_api-bundle. In this case, all dependencies of cos-java-sdk are installed independently, so more space will be used.<groupId>com.qcloud</groupId><artifactId>cos_api-bundle</artifactId><version>5.6.35</version>
/. When creating a file, you don't need to create a directory. For example, when you create a file with the object key of xxx/yyy/zzz.txt, set the key to xxx/yyy/zzz.txt instead of creating the object xxx/yyy/. Directories are separated by / to show the hierarchy when displayed in the console. To create a directory object, use the following sample code:String bucketName = "examplebucket-1250000000";String key = "folder/images/";// A directory object is an empty file that ends with /, where a byte stream with a length of 0 is uploadedInputStream input = new ByteArrayInputStream(new byte[0]);ObjectMetadata objectMetadata = new ObjectMetadata();objectMetadata.setContentLength(0);PutObjectRequest putObjectRequest =new PutObjectRequest(bucketName, key, input, objectMetadata);PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
ClientConfig class. Below is the sample code:// Initialize user authentication information (`secretId` and `secretKey`).String secretId = "COS_SECRETID";String secretKey = "COS_SECRETKEY";COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);// Set the bucket region. For abbreviations of COS regions, please visit https://www.tencentcloud.com/document/product/436/6224.ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing-1"));// Configure HTTPS.clientConfig.setHttpProtocol(HttpProtocol.https);// Generate a COS client.COSClient cosClient = new COSClient(cred, clientConfig);
ClientConfig class. Below is the sample code:// Initialize user authentication information (`secretId` and `secretKey`).String secretId = "COS_SECRETID";String secretKey = "COS_SECRETKEY";COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);// Set the bucket region. For abbreviations of COS regions, please visit https://www.tencentcloud.com/document/product/436/6224.ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing-1"));// Configure a proxy (both the IP and port need to be set).// Set the proxy IP (or pass an endpoint).clientConfig.setHttpProxyIp("192.168.2.3");// Set the proxy port.clientConfig.setHttpProxyPort(8080);// Generate a COS client.COSClient cosClient = new COSClient(cred, clientConfig);
EndpointBuilder?buildGeneralApiEndpoint and buildGetServiceApiEndpoint functions in the EndpointBuilder API to specify the remote endpoints for general API requests and GETService requests respectively. Below is the sample code:// Step 1. Implement the two functions in the EndpointBuilder API.class SelfDefinedEndpointBuilder implements EndpointBuilder {@Overridepublic String buildGeneralApiEndpoint(String bucketName) {return String.format("%s.%s", bucketName, "mytest.com");}@Overridepublic String buildGetServiceApiEndpoint() {return "service.mytest.com";}}// Step 2. Initialize the client.String secretId = "COS_SECRETID";String secretKey = "COS_SECRETKEY";COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);SelfDefinedEndpointBuilder selfDefinedEndpointBuilder = new SelfDefinedEndpointBuilder();ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing"));clientConfig .setEndpointBuilder(selfDefinedEndpointBuilder);COSClient cosClient = new COSClient(cred, clientConfig);
/ prefix to key values used in SDK operations such as upload, download, and batch delete?/ for COS objects. For example, if you set the key value of a COS object to exampleobject, you can access it using the http://cos.ap-guangzhou.myqcloud.com/exampleobject URL./ in a batch deletion request; otherwise, object deletion will fail.getProgress() method of Upload to get the TransferProgress class.prefix parameter to specify the directory prefix.COSClient.shutdown() method to shut down the instance when it is no longer needed.
If you need to create a new instance, shut down the previous one first. We recommend you use only one COSClient in a thread and call COSClient.shutdown() after all programs end and exit.TransferManager.shutdownNow(false) after all programs end and exit.
In addition, if another COSClient is reused when a TransferManager instance is created, add the parameter false (i.e., TransferManager.shutdownNow(false)) when closing the instance. This avoids closing the reused COSClients and thus causing errors in other places where it is used.Feedback