Search in sources :

Example 31 with CloudSDKException

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

the class TestQCloudVODServiceImpl method uploadVideo.

@Test
public void uploadVideo() {
    String filePath = TestQCloudVODServiceImpl.class.getClassLoader().getResource("test.mp4").getPath();
    File mediaFile = new File(filePath);
    filePath = TestQCloudVODServiceImpl.class.getClassLoader().getResource("test-p.jpg").getPath();
    File coverFile = new File(filePath);
    try {
        vodService.uploadVideo(mediaFile, coverFile);
    } catch (CloudSDKException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) File(java.io.File) Test(org.junit.Test)

Example 32 with CloudSDKException

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

the class TencentOCRServiceImpl method imageUrlOCR.

/**
 * {@inheritDoc}
 */
@Override
public String imageUrlOCR(String imageUrl) throws CloudSDKException {
    VinOCRRequest req = new VinOCRRequest();
    req.setImageUrl(imageUrl);
    try {
        VinOCRResponse resp = ocrClient.VinOCR(req);
        return resp.getVin();
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
}
Also used : TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) VinOCRResponse(com.tencentcloudapi.ocr.v20181119.models.VinOCRResponse) VinOCRRequest(com.tencentcloudapi.ocr.v20181119.models.VinOCRRequest)

Example 33 with CloudSDKException

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

the class TencentOCRServiceImpl method imageBase64OCR.

/**
 * {@inheritDoc}
 */
@Override
public String imageBase64OCR(String imageBase64) throws CloudSDKException {
    VinOCRRequest req = new VinOCRRequest();
    req.setImageBase64(imageBase64);
    try {
        VinOCRResponse resp = ocrClient.VinOCR(req);
        return resp.getVin();
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
}
Also used : TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) VinOCRResponse(com.tencentcloudapi.ocr.v20181119.models.VinOCRResponse) VinOCRRequest(com.tencentcloudapi.ocr.v20181119.models.VinOCRRequest)

Example 34 with CloudSDKException

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

the class TencentOCRServiceImpl method getTempCredential.

/**
 * {@inheritDoc}
 */
@Override
public TempCredential getTempCredential(long durationSecond) throws CloudSDKException {
    GetFederationTokenRequest request = new GetFederationTokenRequest();
    request.setName("ocr");
    request.setDurationSeconds(durationSecond);
    request.setPolicy("{\"version\": \"2.0\", \"statement\": [{\"action\": [\"ocr:*\"], \"resource\": \"*\", \"effect\": \"allow\"}]}");
    try {
        GetFederationTokenResponse response = cosClient.GetFederationToken(request);
        Credentials credential = response.getCredentials();
        TempCredential tempCredential = new TempCredential();
        tempCredential.setSecretId(credential.getTmpSecretId());
        tempCredential.setSecretKey(credential.getTmpSecretKey());
        tempCredential.setToken(credential.getToken());
        tempCredential.setExpiredTime(response.getExpiredTime());
        return tempCredential;
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
}
Also used : TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TempCredential(com.mizhousoft.cloudsdk.TempCredential) GetFederationTokenResponse(com.tencentcloudapi.sts.v20180813.models.GetFederationTokenResponse) GetFederationTokenRequest(com.tencentcloudapi.sts.v20180813.models.GetFederationTokenRequest) Credentials(com.tencentcloudapi.sts.v20180813.models.Credentials)

Example 35 with CloudSDKException

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

the class COSObjectStorageServiceImpl method putObject.

/**
 * {@inheritDoc}
 */
@Override
public void putObject(String bucketName, String objectName, InputStream input, long contentLength, String contentType) throws CloudSDKException {
    try {
        com.qcloud.cos.model.ObjectMetadata metadata = new com.qcloud.cos.model.ObjectMetadata();
        metadata.setContentLength(contentLength);
        metadata.setContentType(contentType);
        cosClient.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)

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