릴리스 노트
제품 공지
<groupId>com.qcloud</groupId><artifactId>cos_api-bundle</artifactId><version>5.6.35</version>
<groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.3</version>
<groupId>com.qcloud</groupId><artifactId>cos_api-bundle</artifactId><version>5.6.35</version>
<groupId>com.qcloud</groupId><artifactId>cos_api-bundle</artifactId><version>5.6.35</version>
/로 끝나는 객체입니다. 파일 생성 시 디렉터리를 생성할 필요가 없습니다. 예를 들어 객체 키가 xxx/yyy/zzz.txt인 파일을 생성할 때는 key를 xxx/yyy/zzz.txt로 설정하면 되고 xxx/yyy/ 객체를 생성할 필요가 없습니다. 콘솔에서 표시할 때 /로 분리되어 디렉터리 계층적 효과를 나타내지만, 해당 디렉터리 객체는 존재하지 않습니다. 디렉터리 객체를 생성하려면 아래 예시 코드를 사용할 수 있습니다.String bucketName = "examplebucket-1250000000";String key = "folder/images/";// 디렉터리 객체는 /로 끝나는 빈 파일이며, 길이가 0인 byte 스트림을 업로드함InputStream 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);
// 사용자의 개인 정보(secretId, secretKey) 초기화String secretId = "COS_SECRETID";String secretKey = "COS_SECRETKEY";COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);// bucket의 리전 설정. COS 리전의 약칭은 https://www.tencentcloud.com/document/product/436/6224 참고ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing-1"));// https 사용 설정clientConfig.setHttpProtocol(HttpProtocol.https);// cos 클라이언트 생성COSClient cosClient = new COSClient(cred, clientConfig);
// 사용자의 개인 정보(secretId, secretKey) 초기화String secretId = "COS_SECRETID";String secretKey = "COS_SECRETKEY";COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);// bucket의 리전 설정. COS 리전의 약칭은 https://www.tencentcloud.com/document/product/436/6224 참고ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing-1"));// 사용할 프록시 설정(IP와 포트를 함께 설정해야 함)// 프록시 IP 설정(도메인 입력 가능)clientConfig.setHttpProxyIp("192.168.2.3");// 프록시 포트 설정clientConfig.setHttpProxyPort(8080);// cos 클라이언트 생성COSClient cosClient = new COSClient(cred, clientConfig);
// 1단계: EndpointBuilder 인터페이스의 두 가지 함수 구현class SelfDefinedEndpointBuilder implements EndpointBuilder {@Overridepublic String buildGeneralApiEndpoint(String bucketName) {return String.format("%s.%s", bucketName, "mytest.com");}@Overridepublic String buildGetServiceApiEndpoint() {return "service.mytest.com";}}// 2단계: 클라이언트 초기화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);
/를 추가해야 하나요?/ 접두사가 필요 없습니다. 예를 들어 객체 key 값을 exampleobject로 업로드 객체로 설정하면 URL: http://cos.ap-guangzhou.myqcloud.com/exampleobject로 액세스할 수 있습니다./로 시작하는 key를 넣지 마십시오. 객체 삭제에 실패할 수 있습니다.CRC64 localCRC = new CRC64();// 로컬 crc64 계산localCRC.update();//...// COS 가 반환한 CRC 를 Long으로 변환cosCRC = crc64ToLong(strCOSCRC);// 비교if (cosCRC == localCRC.getValue()) {xxx}// COS에서 반환된 CRC64를 1개 Java 내 Long으로 변환하는 데 사용long crc64ToLong(String crc64) {if (crc64.charAt(0) == '-') {return negativeCrc64ToLong(crc64);} else {return positiveCrc64ToLong(crc64);}}long positiveCrc64ToLong(String strCrc64) {BigInteger crc64 = new BigInteger(strCrc64);BigInteger maxLong = new BigInteger(Long.toString(Long.MAX_VALUE));int maxCnt = 0;while (crc64.compareTo(maxLong) > 0) {crc64 = crc64.subtract(maxLong);maxCnt++;}return crc64.longValue() + Long.MAX_VALUE * maxCnt;}long negativeCrc64ToLong(String strCrc64) {BigInteger crc64 = new BigInteger(strCrc64);BigInteger minLong = new BigInteger(Long.toString(Long.MIN_VALUE));int minCnt = 0;while (crc64.compareTo(minLong) < 0) {crc64 = crc64.subtract(minLong);minCnt++;}return crc64.longValue() + Long.MIN_VALUE * minCnt;}
피드백