本文整理汇总了Java中com.qcloud.cos.ClientConfig类的典型用法代码示例。如果您正苦于以下问题:Java ClientConfig类的具体用法?Java ClientConfig怎么用?Java ClientConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientConfig类属于com.qcloud.cos包,在下文中一共展示了ClientConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: UseTemporyTokenUploadAndDownload
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public static void UseTemporyTokenUploadAndDownload() {
// 使用云api秘钥,可以获取一个临时secret id,secret key和session token,
BasicSessionCredentials cred = getSessionCredential();
// 设置区域, 这里设置为北京一区
ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing-1"));
// 生成cos客户端对象
COSClient cosClient = new COSClient(cred, clientConfig);
// 上传的bucket名字
String bucketName = "rabbitliutj-1000000";
// 上传object, 建议20M以下的文件使用该接口
File localFile = new File("src/test/resources/len5M.txt");
String key = "/upload_single_demo5M.txt";
// 上传
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
ObjectMetadata objectMetadata = new ObjectMetadata();
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
System.out.println(putObjectResult.getMetadata());
// 下载
File downFile = new File("src/test/resources/len5M_down.txt");
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
ObjectMetadata downObjectMeta = cosClient.getObject(getObjectRequest, downFile);
// 关闭客户端(关闭后台线程)
cosClient.shutdown();
}
示例2: CreateBucketDemo
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public static void CreateBucketDemo() {
// 1 初始化用户身份信息(appid, secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
// 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 = "publicreadbucket-1251668577";
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
// 设置bucket的权限为PublicRead(公有读私有写), 其他可选有私有读写, 公有读私有写
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
Bucket bucket = cosclient.createBucket(createBucketRequest);
// 关闭客户端
cosclient.shutdown();
}
示例3: GenerateSimplePresignedDownloadUrl
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public static void GenerateSimplePresignedDownloadUrl() {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
// 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);
// 设置签名过期时间(可选), 若未进行设置则默认使用ClientConfig中的签名过期时间(5分钟)
// 这里设置签名在半个小时后过期
Date expirationDate = new Date(System.currentTimeMillis() + 30 * 60 * 1000);
req.setExpiration(expirationDate);
URL url = cosclient.generatePresignedUrl(req);
System.out.println(url.toString());
}
示例4: GeneratePresignedDownloadUrlAnonymous
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
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();
}
示例5: AbstractCosHttpClient
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public AbstractCosHttpClient(ClientConfig config) {
super();
this.config = config;
this.connectionManager = new PoolingHttpClientConnectionManager();
this.connectionManager.setMaxTotal(config.getMaxConnectionsCount());
this.connectionManager.setDefaultMaxPerRoute(config.getMaxConnectionsCount());
this.connectionManager.setValidateAfterInactivity(1);
HttpClientBuilder httpClientBuilder =
HttpClients.custom().setConnectionManager(connectionManager);
if (config.getHttpProxyIp() != null && config.getHttpProxyPort() != 0) {
HttpHost proxy = new HttpHost(config.getHttpProxyIp(), config.getHttpProxyPort());
httpClientBuilder.setProxy(proxy);
}
this.httpClient = httpClientBuilder.build();
this.requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(this.config.getConnectionRequestTimeout())
.setConnectTimeout(this.config.getConnectionTimeout())
.setSocketTimeout(this.config.getSocketTimeout()).build();
this.idleConnectionMonitor = new IdleConnectionMonitorThread(this.connectionManager);
this.idleConnectionMonitor.setDaemon(true);
this.idleConnectionMonitor.start();
}
示例6: DeleteBucketDemo
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public static void DeleteBucketDemo() {
// 1 初始化用户身份信息(appid, secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
// 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 = "publicreadbucket-1251668577";
// 删除bucket
cosclient.deleteBucket(bucketName);
// 关闭客户端
cosclient.shutdown();
}
示例7: JudgeBucketExistDemo
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public static void JudgeBucketExistDemo() {
// 1 初始化用户身份信息(appid, secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
// 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);
String bucketName = "publicreadbucket-1251668577";
// 判断bucket是否存在
cosclient.doesBucketExist(bucketName);
// 关闭客户端
cosclient.shutdown();
}
示例8: GeneratePresignedDownloadUrlWithOverrideResponseHeader
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public static void GeneratePresignedDownloadUrlWithOverrideResponseHeader() {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
// 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);
// 设置下载时返回的http头
ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides();
String responseContentType = "image/x-icon";
String responseContentLanguage = "zh-CN";
String responseContentDispositon = "filename=\"abc.txt\"";
String responseCacheControl = "no-cache";
String cacheExpireStr =
DateUtils.formatRFC822Date(new Date(System.currentTimeMillis() + 24 * 3600 * 1000));
responseHeaders.setContentType(responseContentType);
responseHeaders.setContentLanguage(responseContentLanguage);
responseHeaders.setContentDisposition(responseContentDispositon);
responseHeaders.setCacheControl(responseCacheControl);
responseHeaders.setExpires(cacheExpireStr);
req.setResponseHeaders(responseHeaders);
// 设置签名过期时间(可选), 若未进行设置则默认使用ClientConfig中的签名过期时间(5分钟)
// 这里设置签名在半个小时后过期
Date expirationDate = new Date(System.currentTimeMillis() + 30 * 60 * 1000);
req.setExpiration(expirationDate);
URL url = cosclient.generatePresignedUrl(req);
System.out.println(url.toString());
}
示例9: DefaultCosHttpClient
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public DefaultCosHttpClient(ClientConfig clientConfig) {
super();
this.errorResponseHandler = new CosErrorResponseHandler();
this.clientConfig = clientConfig;
this.connectionManager = new PoolingHttpClientConnectionManager();
initHttpClient();
}
示例10: init
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
private void init(){
Credentials credentials = new Credentials(config.getQcloudAppId(), config.getQcloudSecretId(),
config.getQcloudSecretKey());
//初始化客户端配置
ClientConfig clientConfig = new ClientConfig();
//设置bucket所在的区域,华南:gz 华北:tj 华东:sh
clientConfig.setRegion(config.getQcloudRegion());
client = new COSClient(clientConfig, credentials);
}
示例11: TencentCOSImpl
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public TencentCOSImpl(TencentCOSConfig tencentCOSConfig) {
this.tencentCOSConfig = tencentCOSConfig;
COSCredentials cred = new BasicCOSCredentials(tencentCOSConfig.getAppId(), tencentCOSConfig.getSecretId(),
tencentCOSConfig.getSecretKey());
ClientConfig clientConfig = new ClientConfig(new Region(tencentCOSConfig.getRegion()));
cosClient = new COSClient(cred, clientConfig);
}
示例12: main
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public static void main(String[] args) {
COSCredentials cred = new BasicCOSCredentials("1251505282", "AKIDCXrebct3IXl0HXrvcHHLYp6UpKwMlFY0", "kaQEEFIMRYhr2OqImHoR5jQbgow7KYn2");
ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"));
COSClient cosClient = new COSClient(cred, clientConfig);
String bucketName = "minsx";
File localFile = new File("E:\\document\\编程文档\\Java真题库_电子书.pdf");
String key = "/腾讯-COS.pdf";
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
cosClient.shutdown();
new CosClientException("");
new CosServiceException("");
//String result = cosClient.statFile(new StatFileRequest(bucketName, "/腾讯-COS.pdf"));
String result = "{\"code\":0,\"message\":\"SUCCESS\",\"request_id\":\"NWEwMTlkMTNfZTlhMDY4NjRfOTRkZl8yMTkwYjA=\",\"data\":{\"access_url\":\"http://minsx-1251505282.file.myqcloud.com/%E8%85%BE%E8%AE%AF-COS.pdf\",\"authority\":\"eInvalid\",\"biz_attr\":\"\",\"ctime\":1509793525,\"custom_headers\":{},\"filelen\":3032065,\"filesize\":3032065,\"forbid\":0,\"mtime\":1509793525,\"sha\":\"8d32e1cc59a978a84556ab38fa9ca7ebbcdd7b04\",\"slicesize\":1048576,\"source_url\":\"http://minsx-1251505282.cossh.myqcloud.com/%E8%85%BE%E8%AE%AF-COS.pdf\"}}\r\n";
System.out.println(result);
JSONObject jsonObject = JSON.parseObject(result);
System.out.println("code = "+jsonObject.get("code"));
System.out.println("message = "+jsonObject.get("message"));
System.out.println("access_url = "+jsonObject.getJSONObject("data").get("access_url"));
System.out.println("authority = "+jsonObject.getJSONObject("data").get("authority"));
System.out.println("biz_attr = "+jsonObject.getJSONObject("data").get("biz_attr"));
System.out.println("ctime = "+jsonObject.getJSONObject("data").get("ctime"));
System.out.println("custom_headers = "+jsonObject.getJSONObject("data").get("custom_headers"));
System.out.println("filelen = "+jsonObject.getJSONObject("data").get("filelen"));
System.out.println("filesize = "+jsonObject.getJSONObject("data").get("filesize"));
System.out.println("forbid = "+jsonObject.getJSONObject("data").get("forbid"));
System.out.println("mtime = "+jsonObject.getJSONObject("data").get("mtime"));
System.out.println("sha = "+jsonObject.getJSONObject("data").get("sha"));
System.out.println("slicesize = "+jsonObject.getJSONObject("data").get("slicesize"));
System.out.println("source_url = "+jsonObject.getJSONObject("data").get("source_url"));
System.out.println(new Date(1509793525000L));
}
示例13: init
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
private void init() {
Credentials credentials = new Credentials(config.getQcloudAppId(), config.getQcloudSecretId(),
config.getQcloudSecretKey());
//初始化客户端配置
ClientConfig clientConfig = new ClientConfig();
//设置bucket所在的区域,华南:gz 华北:tj 华东:sh
clientConfig.setRegion(config.getQcloudRegion());
client = new COSClient(clientConfig, credentials);
}
示例14: AbstractCosHttpClient
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public AbstractCosHttpClient(ClientConfig config) {
super();
this.config = config;
this.connectionManager = new PoolingHttpClientConnectionManager();
this.connectionManager.setMaxTotal(config.getMaxConnectionsCount());
this.connectionManager.setDefaultMaxPerRoute(config.getMaxConnectionsCount());
this.httpClient = HttpClients.custom().setConnectionManager(connectionManager).build();
this.requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(this.config.getConnectionRequestTimeout())
.setConnectTimeout(this.config.getConnectionTimeout())
.setSocketTimeout(this.config.getSocketTimeout())
.build();
this.idleConnectionMonitor = new IdleConnectionMonitorThread(this.connectionManager);
this.idleConnectionMonitor.start();
}
示例15: FileOp
import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public FileOp(ClientConfig config, Credentials cred, AbstractCosHttpClient client) {
super(config, cred, client);
}