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());
}
}
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());
}
}
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;
}
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));
}
}
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());
}
}
Aggregations