• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ClientConfig类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.qcloud.cos.ClientConfig的典型用法代码示例。如果您正苦于以下问题:Java ClientConfig类的具体用法?Java ClientConfig怎么用?Java ClientConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClientConfig类属于com.qcloud.cos包,在下文中一共展示了ClientConfig类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:27,代码来源:TemporyTokenDemo.java


示例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();
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:19,代码来源:BucketDemo.java


示例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());
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:22,代码来源:GeneratePresignedUrlDemo.java


示例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();
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:20,代码来源:GeneratePresignedUrlDemo.java


示例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();
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v4,代码行数:23,代码来源:AbstractCosHttpClient.java


示例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();
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:16,代码来源:BucketDemo.java


示例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();
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:16,代码来源:BucketDemo.java


示例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());
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:36,代码来源:GeneratePresignedUrlDemo.java


示例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();
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:8,代码来源:DefaultCosHttpClient.java


示例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);
}
 
开发者ID:zhaoqicheng,项目名称:renren-fast,代码行数:12,代码来源:QcloudCloudStorageService.java


示例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);
}
 
开发者ID:MinsxCloud,项目名称:minsx-ccs,代码行数:8,代码来源:TencentCOSImpl.java


示例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));
	
}
 
开发者ID:MinsxCloud,项目名称:minsx-ccs,代码行数:39,代码来源:App.java


示例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);
}
 
开发者ID:davichi11,项目名称:my-spring-boot-project,代码行数:12,代码来源:QcloudAbstractCloudStorageService.java


示例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();
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk,代码行数:16,代码来源:AbstractCosHttpClient.java


示例15: FileOp

import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public FileOp(ClientConfig config, Credentials cred, AbstractCosHttpClient client) {
    super(config, cred, client);
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v4,代码行数:4,代码来源:FileOp.java


示例16: FolderOp

import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public FolderOp(ClientConfig config, Credentials cred, AbstractCosHttpClient client) {
    super(config, cred, client);
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v4,代码行数:4,代码来源:FolderOp.java


示例17: BaseOp

import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public BaseOp(ClientConfig config, Credentials cred, AbstractCosHttpClient httpClient) {
    super();
    this.config = config;
    this.cred = cred;
    this.httpClient = httpClient;
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v4,代码行数:7,代码来源:BaseOp.java


示例18: setConfig

import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public void setConfig(ClientConfig config) {
    this.config = config;
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v4,代码行数:4,代码来源:BaseOp.java


示例19: DefaultCosHttpClient

import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public DefaultCosHttpClient(ClientConfig config) {
    super(config);
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v4,代码行数:4,代码来源:DefaultCosHttpClient.java


示例20: FileOp

import com.qcloud.cos.ClientConfig; //导入依赖的package包/类
public FileOp(ClientConfig config, Credentials cred, AbstractCosHttpClient client) {
	super(config, cred, client);
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk,代码行数:4,代码来源:FileOp.java



注:本文中的com.qcloud.cos.ClientConfig类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AsyncLogger类代码示例发布时间:2022-05-22
下一篇:
Java Setter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap