use of com.jeesuite.cos.CUploadResult in project jeesuite-libs by vakinge.
the class MinioProvider method upload.
@Override
public CUploadResult upload(CUploadObject object) {
try {
String bucketName = object.getBucketName();
if (StringUtils.isEmpty(bucketName)) {
throw new JeesuiteBaseException("BucketName 不能为空");
}
String fileKey = object.getFileKey();
InputStream inputStream = object.getInputStream();
byte[] objectBytes = object.getBytes();
ObjectWriteResponse objectWriteResponse = null;
long size = 0;
if (object.getFile() != null) {
objectWriteResponse = minioClient.uploadObject(UploadObjectArgs.builder().bucket(bucketName).filename(object.getFile().getAbsolutePath()).object(fileKey).contentType(object.getMimeType()).build());
size = object.getFile().length();
} else if (objectBytes != null) {
byte[] bytes = objectBytes;
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
objectWriteResponse = minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(fileKey).contentType(object.getMimeType()).stream(bis, bytes.length, -1).build());
size = bytes.length;
bis.close();
} else if (inputStream != null) {
objectWriteResponse = minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(fileKey).contentType(object.getMimeType()).stream(inputStream, inputStream.available(), -1).build());
size = inputStream.available();
} else {
throw new JeesuiteBaseException("upload object is NULL");
}
if (objectWriteResponse != null) {
CUploadResult uploadResult = new CUploadResult(fileKey, getDownloadUrl(object.getBucketName(), fileKey, 300), null);
uploadResult.setMimeType(object.getMimeType());
uploadResult.setFileSize(size);
return uploadResult;
}
} catch (JeesuiteBaseException jbex) {
throw jbex;
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
use of com.jeesuite.cos.CUploadResult in project jeesuite-libs by vakinge.
the class QiniuProvider method upload.
@Override
public CUploadResult upload(CUploadObject object) {
String fileKey = object.getFileKey();
String bucketName = buildBucketName(object.getBucketName());
try {
Response res = null;
String upToken = getUpToken(bucketName);
if (object.getFile() != null) {
res = uploadManager.put(object.getFile(), fileKey, upToken);
} else if (object.getBytes() != null) {
res = uploadManager.put(object.getBytes(), fileKey, upToken);
} else if (object.getInputStream() != null) {
res = uploadManager.put(object.getInputStream(), fileKey, upToken, null, object.getMimeType());
} else {
throw new IllegalArgumentException("upload object is NULL");
}
if (res.isOK()) {
return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), null);
}
} catch (QiniuException e) {
processQiniuException(object.getFileKey(), e);
}
return null;
}
use of com.jeesuite.cos.CUploadResult in project jeesuite-libs by vakinge.
the class AliyunProvider method upload.
@Override
public CUploadResult upload(CUploadObject object) {
try {
PutObjectRequest request;
String fileKey = object.getFileKey();
String bucketName = buildBucketName(object.getBucketName());
if (object.getFile() != null) {
request = new PutObjectRequest(bucketName, fileKey, object.getFile());
} else if (object.getBytes() != null) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(object.getBytes());
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(object.getFileSize());
request = new PutObjectRequest(bucketName, fileKey, inputStream, objectMetadata);
} else if (object.getInputStream() != null) {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(object.getFileSize());
request = new PutObjectRequest(bucketName, fileKey, object.getInputStream(), objectMetadata);
} else {
throw new IllegalArgumentException("upload object is NULL");
}
PutObjectResult result = ossClient.putObject(request);
if (result.getResponse() == null || result.getResponse().isSuccessful()) {
return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getServerCRC().toString());
} else {
throw new RuntimeException(result.getResponse().getErrorResponseAsString());
}
} catch (OSSException e) {
throw new RuntimeException(e.getErrorMessage());
}
}
use of com.jeesuite.cos.CUploadResult in project jeesuite-libs by vakinge.
the class QcloudProvider method upload.
@Override
public CUploadResult upload(CUploadObject object) {
PutObjectRequest request;
String fileKey = object.getFileKey();
String bucketName = buildBucketName(object.getBucketName());
if (object.getFile() != null) {
request = new PutObjectRequest(bucketName, fileKey, object.getFile());
} else if (object.getBytes() != null) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(object.getBytes());
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(object.getFileSize());
request = new PutObjectRequest(bucketName, fileKey, inputStream, objectMetadata);
} else if (object.getInputStream() != null) {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(object.getFileSize());
request = new PutObjectRequest(bucketName, fileKey, object.getInputStream(), objectMetadata);
} else {
throw new IllegalArgumentException("upload object is NULL");
}
try {
if (object.getFileSize() > conf.getMaxAllowdSingleFileSize()) {
Upload upload = transferManager.upload(request);
com.qcloud.cos.model.UploadResult result = upload.waitForUploadResult();
return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getCrc64Ecma());
} else {
PutObjectResult result = cosclient.putObject(request);
return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getContentMd5());
}
} catch (Exception e) {
e.printStackTrace();
throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
}
}
Aggregations