Search in sources :

Example 26 with JeesuiteBaseException

use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class AliyunProvider method getObjectMetadata.

@Override
public CObjectMetadata getObjectMetadata(String bucketName, String fileKey) {
    try {
        bucketName = buildBucketName(bucketName);
        fileKey = resolveFileKey(bucketName, fileKey);
        ObjectMetadata metadata = ossClient.getObjectMetadata(bucketName, fileKey);
        CObjectMetadata objectMetadata = new CObjectMetadata();
        objectMetadata.setCreateTime(metadata.getLastModified());
        objectMetadata.setMimeType(metadata.getContentType());
        objectMetadata.setFilesize(metadata.getContentLength());
        objectMetadata.setHash(metadata.getContentMD5());
        objectMetadata.setExpirationTime(metadata.getExpirationTime());
        objectMetadata.setCustomMetadatas(metadata.getUserMetadata());
        return objectMetadata;
    } catch (Exception e) {
        throw new JeesuiteBaseException(500, e.getMessage());
    }
}
Also used : CObjectMetadata(com.mendmix.cos.CObjectMetadata) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) CObjectMetadata(com.mendmix.cos.CObjectMetadata) ObjectMetadata(com.aliyun.oss.model.ObjectMetadata) OSSException(com.aliyun.oss.OSSException) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) IOException(java.io.IOException)

Example 27 with JeesuiteBaseException

use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class HuaweicloudProvider method getObjectInputStream.

@Override
public InputStream getObjectInputStream(String bucketName, String fileKey) {
    if (!existsBucket(bucketName)) {
        logger.info("Bucket[{}]不存在", bucketName);
        return null;
    }
    try {
        ObsObject object = obsClient.getObject(bucketName, fileKey);
        InputStream inputStream = object.getObjectContent();
        return inputStream;
    } catch (Exception e) {
        logger.error("获取流失败, bucketName={}, fileKey={}, e={}", bucketName, fileKey, ExceptionUtils.getMessage(e));
        throw new JeesuiteBaseException(e.getMessage());
    }
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ObsObject(com.obs.services.model.ObsObject) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException)

Example 28 with JeesuiteBaseException

use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class HuaweicloudProvider method upload.

@Override
public CUploadResult upload(CUploadObject object) {
    String bucketName = object.getBucketName();
    if (StringUtils.isBlank(bucketName)) {
        throw new JeesuiteBaseException("BucketName 不能为空");
    }
    InputStream inputStream = object.getInputStream();
    File file = object.getFile();
    String fileKey = object.getFileKey();
    byte[] bytes = object.getBytes();
    long size = 0;
    logger.info("bucknetName={}, fileKey={}", bucketName, fileKey);
    PutObjectResult putObjectResult = null;
    try {
        if (file != null) {
            ObjectMetadata metadata = new ObjectMetadata();
            metadata.setContentType(object.getMimeType());
            putObjectResult = obsClient.putObject(bucketName, fileKey, file, metadata);
            size = file.length();
        } else if (bytes != null) {
            ByteArrayInputStream input = new ByteArrayInputStream(bytes);
            putObjectResult = obsClient.putObject(bucketName, fileKey, input);
            size = bytes.length;
            input.close();
        } else if (inputStream != null) {
            putObjectResult = obsClient.putObject(bucketName, fileKey, inputStream);
            size = inputStream.available();
        } else {
            throw new JeesuiteBaseException("upload object is NULL");
        }
        if (putObjectResult != null) {
            AccessControlList acl = new AccessControlList();
            if (!isBucketPrivate(bucketName)) {
                acl = AccessControlList.REST_CANNED_PUBLIC_READ;
            }
            obsClient.setObjectAcl(bucketName, fileKey, acl);
            CUploadResult uploadResult = new CUploadResult(fileKey, getDownloadUrl(object.getBucketName(), fileKey, 300), null);
            uploadResult.setMimeType(object.getMimeType());
            uploadResult.setFileSize(size);
            return uploadResult;
        }
    } catch (Exception e) {
        logger.error("上传文件出错, bucketName={}, fileKey={}, e={}", bucketName, fileKey, ExceptionUtils.getMessage(e));
        throw new JeesuiteBaseException(e.getMessage());
    }
    return null;
}
Also used : AccessControlList(com.obs.services.model.AccessControlList) CUploadResult(com.mendmix.cos.CUploadResult) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) PutObjectResult(com.obs.services.model.PutObjectResult) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) File(java.io.File) CObjectMetadata(com.mendmix.cos.CObjectMetadata) ObjectMetadata(com.obs.services.model.ObjectMetadata) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException)

Example 29 with JeesuiteBaseException

use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QcloudProvider method getObjectInputStream.

@Override
public InputStream getObjectInputStream(String bucketName, String fileKey) {
    try {
        String _bucketName = buildBucketName(bucketName);
        String _fileKey = resolveFileKey(bucketName, fileKey);
        COSObject cosObject = cosclient.getObject(_bucketName, _fileKey);
        return cosObject.getObjectContent();
    } catch (Exception e) {
        throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
    }
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) COSObject(com.qcloud.cos.model.COSObject) CosServiceException(com.qcloud.cos.exception.CosServiceException) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) IOException(java.io.IOException)

Example 30 with JeesuiteBaseException

use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QcloudProvider method createUploadToken.

// https://github.com/tencentyun/qcloud-cos-sts-sdk/tree/master/java
@Override
public Map<String, Object> createUploadToken(UploadTokenParam param) {
    TreeMap<String, Object> config = new TreeMap<String, Object>();
    config.put("SecretId", conf.getAccessKey());
    config.put("SecretKey", conf.getSecretKey());
    config.put("durationSeconds", param.getExpires());
    config.put("bucket", buildBucketName(param.getBucketName()));
    config.put("region", conf.getRegionName());
    // config.put("allowPrefix", "a.jpg");
    // 密钥的权限列表。简单上传、表单上传和分片上传需要以下的权限,其他权限列表请看
    // https://cloud.tencent.com/document/product/436/31923
    String[] allowActions = new String[] { // 简单上传
    "name/cos:PutObject", // 表单上传、小程序上传
    "name/cos:PostObject", // 分片上传
    "name/cos:InitiateMultipartUpload", "name/cos:ListMultipartUploads", "name/cos:ListParts", "name/cos:UploadPart", "name/cos:CompleteMultipartUpload" };
    config.put("allowActions", allowActions);
    try {
        org.json.JSONObject json = CosStsClient.getCredential(config);
        return json.toMap();
    } catch (IOException e) {
        throw new JeesuiteBaseException("生成临时凭证错误:" + e.getMessage());
    }
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) COSObject(com.qcloud.cos.model.COSObject) CUploadObject(com.mendmix.cos.CUploadObject) IOException(java.io.IOException) TreeMap(java.util.TreeMap)

Aggregations

JeesuiteBaseException (com.mendmix.common.JeesuiteBaseException)44 IOException (java.io.IOException)13 CObjectMetadata (com.mendmix.cos.CObjectMetadata)4 CUploadResult (com.mendmix.cos.CUploadResult)4 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 Request (okhttp3.Request)4 ApiInfo (com.mendmix.common.model.ApiInfo)2 WrapperResponse (com.mendmix.common.model.WrapperResponse)2 BizSystemModule (com.mendmix.gateway.model.BizSystemModule)2 COSObject (com.qcloud.cos.model.COSObject)2 QiniuException (com.qiniu.common.QiniuException)2 InputStreamReader (java.io.InputStreamReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SignatureException (java.security.SignatureException)2 Map (java.util.Map)2