Search in sources :

Example 11 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class COSObjectStorageServiceImpl method getObjectMetadata.

/**
 * {@inheritDoc}
 */
@Override
public ObjectMetadata getObjectMetadata(String bucketName, String objectName) throws CloudSDKException {
    try {
        ObjectMetadata objectMetadata = null;
        com.qcloud.cos.model.ObjectMetadata metadata = cosClient.getObjectMetadata(bucketName, objectName);
        if (null != metadata) {
            objectMetadata = new ObjectMetadata();
            objectMetadata.setContentLength(metadata.getContentLength());
            objectMetadata.setContentMD5(metadata.getContentMD5());
            objectMetadata.setContentType(metadata.getContentType());
            objectMetadata.setLastModified(metadata.getLastModified());
            objectMetadata.setObjectName(objectName);
            return objectMetadata;
        } else {
            throw new CloudSDKException("ObjectName not found.");
        }
    } catch (Throwable e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) ObjectMetadata(com.mizhousoft.cloudsdk.oss.ObjectMetadata)

Example 12 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class COSObjectStorageServiceImpl method copyObject.

/**
 * {@inheritDoc}
 */
@Override
public void copyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey) throws CloudSDKException {
    try {
        CopyObjectRequest request = new CopyObjectRequest(sourceBucketName, sourceKey, destinationBucketName, destinationKey);
        cosClient.copyObject(request);
    } catch (Throwable e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) CopyObjectRequest(com.qcloud.cos.model.CopyObjectRequest)

Example 13 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class AliyunObjectStorageServiceImpl method genPresignedUploadUrl.

/**
 * {@inheritDoc}
 */
@Override
public URL genPresignedUploadUrl(String bucketName, String objectName, long signExpired, String contentMd5) throws CloudSDKException {
    try {
        GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, objectName, HttpMethod.PUT);
        req.setContentMD5(contentMd5);
        Date expirationDate = new Date(System.currentTimeMillis() + signExpired);
        req.setExpiration(expirationDate);
        URL downloadUrl = ossClient.generatePresignedUrl(req);
        return downloadUrl;
    } catch (Throwable e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) GeneratePresignedUrlRequest(com.aliyun.oss.model.GeneratePresignedUrlRequest) Date(java.util.Date) URL(java.net.URL)

Example 14 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class AliyunObjectStorageServiceImpl method putObject.

/**
 * {@inheritDoc}
 */
@Override
public void putObject(String bucketName, String objectName, InputStream input, long contentLength, String contentType) throws CloudSDKException {
    try {
        com.aliyun.oss.model.ObjectMetadata metadata = new com.aliyun.oss.model.ObjectMetadata();
        metadata.setContentLength(contentLength);
        metadata.setContentType(contentType);
        ossClient.putObject(bucketName, objectName, input, metadata);
    } catch (Throwable e) {
        throw new CloudSDKException(e.getMessage(), e);
    } finally {
        try {
            input.close();
        } catch (Throwable e) {
            LOG.error("Close file input stream failed.", e);
        }
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) ObjectMetadata(com.mizhousoft.cloudsdk.oss.ObjectMetadata)

Example 15 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class AliyunObjectStorageServiceImpl method getObjectMetadata.

/**
 * {@inheritDoc}
 */
@Override
public ObjectMetadata getObjectMetadata(String bucketName, String objectName) throws CloudSDKException {
    try {
        ObjectMetadata objectMetadata = null;
        com.aliyun.oss.model.ObjectMetadata metadata = ossClient.getObjectMetadata(bucketName, objectName);
        if (null != metadata) {
            objectMetadata = new ObjectMetadata();
            objectMetadata.setContentLength(metadata.getContentLength());
            objectMetadata.setContentMD5(metadata.getContentMD5());
            objectMetadata.setContentType(metadata.getContentType());
            objectMetadata.setLastModified(metadata.getLastModified());
            objectMetadata.setObjectName(objectName);
            return objectMetadata;
        } else {
            throw new CloudSDKException("ObjectName not found.");
        }
    } catch (Throwable e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) ObjectMetadata(com.mizhousoft.cloudsdk.oss.ObjectMetadata)

Aggregations

CloudSDKException (com.mizhousoft.cloudsdk.CloudSDKException)44 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)14 Test (org.junit.Test)13 URL (java.net.URL)8 ObjectMetadata (com.mizhousoft.cloudsdk.oss.ObjectMetadata)6 File (java.io.File)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 RecognitionResult (com.mizhousoft.cloudsdk.nlp.RecognitionResult)3 Date (java.util.Date)3 GeneratePresignedUrlRequest (com.aliyun.oss.model.GeneratePresignedUrlRequest)2 TempCredential (com.mizhousoft.cloudsdk.TempCredential)2 OSSTempCredential (com.mizhousoft.cloudsdk.oss.OSSTempCredential)2 MediaMeta (com.mizhousoft.cloudsdk.vod.MediaMeta)2 CoverTypeEnum (com.mizhousoft.tencent.vod.constants.CoverTypeEnum)2 MediaTypeEnum (com.mizhousoft.tencent.vod.constants.MediaTypeEnum)2 GeneratePresignedUrlRequest (com.qcloud.cos.model.GeneratePresignedUrlRequest)2 VinOCRRequest (com.tencentcloudapi.ocr.v20181119.models.VinOCRRequest)2 VinOCRResponse (com.tencentcloudapi.ocr.v20181119.models.VinOCRResponse)2 CoverBySnapshotTaskInput (com.tencentcloudapi.vod.v20180717.models.CoverBySnapshotTaskInput)2