use of com.qcloud.cos.auth.AnonymousCOSCredentials in project cos-java-sdk-v5 by tencentyun.
the class GeneratePresignedUrlDemo method GeneratePresignedDownloadUrlAnonymous.
// 获取预签名的下载链接, 用于匿名bucket, 匿名bucket生成的预下载链接不包含签名
public static void GeneratePresignedDownloadUrlAnonymous() {
// 1 初始化用户身份信息, 匿名身份不用传入ak sk
COSCredentials cred = new AnonymousCOSCredentials();
// 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing-1"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket名需包含appid
String bucketName = "mybucket-1251668577";
String key = "aaa.txt";
GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, key, HttpMethodName.GET);
URL url = cosclient.generatePresignedUrl(req);
System.out.println(url.toString());
cosclient.shutdown();
}
use of com.qcloud.cos.auth.AnonymousCOSCredentials in project cos-java-sdk-v5 by tencentyun.
the class GetObjectURLDemo method getObjectUrlWithEndpoint.
public static void getObjectUrlWithEndpoint() {
// getObjectUrl 不需要验证身份信息
COSCredentials cred = new AnonymousCOSCredentials();
// 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
// 设置生成的 url 的协议名
clientConfig.setHttpProtocol(HttpProtocol.https);
// 设置自定义的域名
UserSpecifiedEndpointBuilder endpointBuilder = new UserSpecifiedEndpointBuilder("test.endpoint.com", "service.cos.myqcloud.com");
clientConfig.setEndpointBuilder(endpointBuilder);
// 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
String key = "test/my_test中文.json";
String bucketName = "mybucket-1251668577";
String versionId = "xxxyyyzzz111222333";
System.out.println(cosclient.getObjectUrl(bucketName, key, versionId));
}
use of com.qcloud.cos.auth.AnonymousCOSCredentials in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method testRequestSpecifiedKeyInfoPutGetDel.
@Test
public void testRequestSpecifiedKeyInfoPutGetDel() throws CosServiceException, IOException, InterruptedException {
COSClient cosclient = new COSClient(new AnonymousCOSCredentials(), clientConfig);
File localFile = buildTestFile(1024L);
COSCredentials cosCredentials = new BasicCOSCredentials(secretId, secretKey);
try {
String key = "ut/request-specified-key";
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, localFile);
putObjectRequest.setCosCredentials(cosCredentials);
cosclient.putObject(putObjectRequest);
GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
getObjectRequest.setCosCredentials(cosCredentials);
cosclient.getObject(getObjectRequest);
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucket, key);
deleteObjectRequest.setCosCredentials(cosCredentials);
cosclient.deleteObject(deleteObjectRequest);
} finally {
localFile.delete();
cosclient.shutdown();
}
}
use of com.qcloud.cos.auth.AnonymousCOSCredentials in project cos-java-sdk-v5 by tencentyun.
the class GetObjectURLDemo method getObjectUrlWithVersionId.
public static void getObjectUrlWithVersionId() {
// getObjectUrl 不需要验证身份信息
COSCredentials cred = new AnonymousCOSCredentials();
// 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
// 设置生成的 url 的协议名
clientConfig.setHttpProtocol(HttpProtocol.https);
// 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
String key = "test/my_test中文.json";
String bucketName = "mybucket-1251668577";
String versionId = "xxxyyyzzz111222333";
System.out.println(cosclient.getObjectUrl(bucketName, key, versionId));
}
use of com.qcloud.cos.auth.AnonymousCOSCredentials in project cos-java-sdk-v5 by tencentyun.
the class GetObjectURLDemo method getObjectUrl.
public static void getObjectUrl() {
// getObjectUrl 不需要验证身份信息
COSCredentials cred = new AnonymousCOSCredentials();
// 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
// 设置生成的 url 的协议名
clientConfig.setHttpProtocol(HttpProtocol.https);
// 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
String key = "test/my_test中文.json";
String bucketName = "mybucket-1251668577";
System.out.println(cosclient.getObjectUrl(bucketName, key));
}
Aggregations