Search in sources :

Example 1 with MediaTypeEnum

use of com.mizhousoft.tencent.vod.constants.MediaTypeEnum in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method getMediaType.

private MediaTypeEnum getMediaType(File mediaFile) throws CloudSDKException {
    String extension = FilenameUtils.getExtension(mediaFile.getName());
    MediaTypeEnum mediaType = MediaTypeEnum.get(extension.toLowerCase(Locale.US));
    if (null == mediaType) {
        throw new CloudSDKException("Media type does not supported.");
    }
    return mediaType;
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) MediaTypeEnum(com.mizhousoft.tencent.vod.constants.MediaTypeEnum)

Example 2 with MediaTypeEnum

use of com.mizhousoft.tencent.vod.constants.MediaTypeEnum in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method uploadVideo.

/**
 * {@inheritDoc}
 */
@Override
public String uploadVideo(File mediaFile, File coverFile) throws CloudSDKException {
    MediaTypeEnum mediaType = getMediaType(mediaFile);
    CoverTypeEnum coverType = getCoverType(coverFile);
    COSObjectStorageServiceImpl objectStorageService = null;
    String bucket = null;
    String coverObjectName = null;
    String mediaObjectName = null;
    try {
        ApplyUploadRequest req = new ApplyUploadRequest();
        req.setMediaType(mediaType.getValue());
        req.setCoverType(coverType.getValue());
        ApplyUploadResponse applyResponse = vodClient.ApplyUpload(req);
        COSProfile config = new COSProfile();
        config.setAccessKey(applyResponse.getTempCertificate().getSecretId());
        config.setSecretKey(applyResponse.getTempCertificate().getSecretKey());
        config.setSessionToken(applyResponse.getTempCertificate().getToken());
        config.setRegion(applyResponse.getStorageRegion());
        objectStorageService = new COSObjectStorageServiceImpl();
        objectStorageService.init(config);
        bucket = applyResponse.getStorageBucket();
        objectStorageService.putObject(bucket, applyResponse.getCoverStoragePath(), coverFile);
        coverObjectName = applyResponse.getCoverStoragePath();
        objectStorageService.putObject(bucket, applyResponse.getMediaStoragePath(), mediaFile);
        mediaObjectName = applyResponse.getMediaStoragePath();
        CommitUploadRequest commitRequest = new CommitUploadRequest();
        commitRequest.setVodSessionKey(applyResponse.getVodSessionKey());
        CommitUploadResponse commitResponse = vodClient.CommitUpload(commitRequest);
        // 上传成功后要置为NULL
        coverObjectName = null;
        mediaObjectName = null;
        return commitResponse.getFileId();
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getErrorCode(), e.getMessage(), e);
    } finally {
        cleanUploadFailedFile(bucket, coverObjectName, objectStorageService);
        cleanUploadFailedFile(bucket, mediaObjectName, objectStorageService);
        if (null != objectStorageService) {
            objectStorageService.destory();
        }
    }
}
Also used : CoverTypeEnum(com.mizhousoft.tencent.vod.constants.CoverTypeEnum) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CommitUploadResponse(com.tencentcloudapi.vod.v20180717.models.CommitUploadResponse) ApplyUploadResponse(com.tencentcloudapi.vod.v20180717.models.ApplyUploadResponse) MediaTypeEnum(com.mizhousoft.tencent.vod.constants.MediaTypeEnum) ApplyUploadRequest(com.tencentcloudapi.vod.v20180717.models.ApplyUploadRequest) CommitUploadRequest(com.tencentcloudapi.vod.v20180717.models.CommitUploadRequest) COSProfile(com.mizhousoft.tencent.oss.COSProfile) COSObjectStorageServiceImpl(com.mizhousoft.tencent.oss.COSObjectStorageServiceImpl)

Aggregations

CloudSDKException (com.mizhousoft.cloudsdk.CloudSDKException)2 MediaTypeEnum (com.mizhousoft.tencent.vod.constants.MediaTypeEnum)2 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)2 COSObjectStorageServiceImpl (com.mizhousoft.tencent.oss.COSObjectStorageServiceImpl)1 COSProfile (com.mizhousoft.tencent.oss.COSProfile)1 CoverTypeEnum (com.mizhousoft.tencent.vod.constants.CoverTypeEnum)1 ApplyUploadRequest (com.tencentcloudapi.vod.v20180717.models.ApplyUploadRequest)1 ApplyUploadResponse (com.tencentcloudapi.vod.v20180717.models.ApplyUploadResponse)1 CommitUploadRequest (com.tencentcloudapi.vod.v20180717.models.CommitUploadRequest)1 CommitUploadResponse (com.tencentcloudapi.vod.v20180717.models.CommitUploadResponse)1