Search in sources :

Example 36 with PutObjectResult

use of com.qcloud.cos.model.PutObjectResult in project cos-java-sdk-v5 by tencentyun.

the class ProxyDemo method ProxyUploadDemo.

// 通过代理上传数据
public static void ProxyUploadDemo(String proxyIp, int proxyPort, String username, String password) {
    // 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-shanghai"));
    clientConfig.setHttpProxyIp(proxyIp);
    clientConfig.setHttpProxyPort(proxyPort);
    // 如果代理不需要basic认证无需指定userName和password
    clientConfig.setProxyUsername(username);
    clientConfig.setProxyPassword(password);
    clientConfig.setUseBasicAuth(true);
    // 3 生成cos客户端
    COSClient cosclient = new COSClient(cred, clientConfig);
    // bucket名需包含appid
    String bucketName = "mybucket-1251668577";
    String key = "aaa/bbb.txt";
    try {
        PutObjectResult putObjectResult = cosclient.putObject(bucketName, key, "data");
        // putobjectResult会返回文件的etag
        String etag = putObjectResult.getETag();
    } catch (CosServiceException e) {
        e.printStackTrace();
    } catch (CosClientException e) {
        e.printStackTrace();
    }
    // 关闭客户端
    cosclient.shutdown();
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) CosServiceException(com.qcloud.cos.exception.CosServiceException) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) PutObjectResult(com.qcloud.cos.model.PutObjectResult) CosClientException(com.qcloud.cos.exception.CosClientException) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig)

Example 37 with PutObjectResult

use of com.qcloud.cos.model.PutObjectResult in project cos-java-sdk-v5 by tencentyun.

the class BlindWatermarkDemo method extractBlindWatermark.

public static void extractBlindWatermark(COSClient cosClient) {
    // bucket名需包含appid
    // api 请参考:https://cloud.tencent.com/document/product/436/46782
    String bucketName = "examplebucket-1250000000";
    String key = "qrcode-watermark.png";
    File localFile = new File("E://qrcode-watermark.png");
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
    PicOperations picOperations = new PicOperations();
    picOperations.setIsPicInfo(1);
    List<PicOperations.Rule> ruleList = new LinkedList<>();
    PicOperations.Rule rule = new PicOperations.Rule();
    rule.setBucket(bucketName);
    rule.setFileId("qrcode-watermark-extract.png");
    rule.setRule("watermark/4/type/2/image/aHR0cDovL2V4YW1wbGVidWNrZXQtMTI1MDAwMDAwMC5jb3MuYXAtZ3Vhbmd6aG91Lm15cWNsb3VkLmNvbS9zaHVpeWluLnBuZw==");
    ruleList.add(rule);
    picOperations.setRules(ruleList);
    putObjectRequest.setPicOperations(picOperations);
    try {
        PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
        CIUploadResult ciUploadResult = putObjectResult.getCiUploadResult();
        System.out.println(putObjectResult.getRequestId());
        System.out.println(ciUploadResult.getOriginalInfo().getEtag());
        for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
            System.out.println(ciObject.getLocation());
            System.out.println(ciObject.getWatermarkStatus());
        }
    } catch (CosServiceException e) {
        e.printStackTrace();
    } catch (CosClientException e) {
        e.printStackTrace();
    }
}
Also used : PutObjectResult(com.qcloud.cos.model.PutObjectResult) CosClientException(com.qcloud.cos.exception.CosClientException) PicOperations(com.qcloud.cos.model.ciModel.persistence.PicOperations) CIUploadResult(com.qcloud.cos.model.ciModel.persistence.CIUploadResult) LinkedList(java.util.LinkedList) CosServiceException(com.qcloud.cos.exception.CosServiceException) File(java.io.File) PutObjectRequest(com.qcloud.cos.model.PutObjectRequest) CIObject(com.qcloud.cos.model.ciModel.persistence.CIObject)

Aggregations

PutObjectResult (com.qcloud.cos.model.PutObjectResult)37 PutObjectRequest (com.qcloud.cos.model.PutObjectRequest)25 File (java.io.File)20 COSClient (com.qcloud.cos.COSClient)14 ClientConfig (com.qcloud.cos.ClientConfig)14 CosServiceException (com.qcloud.cos.exception.CosServiceException)14 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)14 Region (com.qcloud.cos.region.Region)14 CosClientException (com.qcloud.cos.exception.CosClientException)12 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)11 COSCredentials (com.qcloud.cos.auth.COSCredentials)11 IOException (java.io.IOException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 CIObject (com.qcloud.cos.model.ciModel.persistence.CIObject)4 CIUploadResult (com.qcloud.cos.model.ciModel.persistence.CIUploadResult)4 PicOperations (com.qcloud.cos.model.ciModel.persistence.PicOperations)4 InputStream (java.io.InputStream)4 LinkedList (java.util.LinkedList)4 Test (org.junit.Test)4 FileOperationException (run.halo.app.exception.FileOperationException)3