製品アップデート情報
製品のお知らせ
<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);
// ユーザーID情報(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);
// ユーザーID情報(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インターフェースの中の2つの関数を実装します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;}
フィードバック