use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class HttpUtil method doGet.
public static String doGet(@NonNull String url, @Nullable Map<String, String> param, @Nullable Map<String, String> headers) {
SdkHttpFullResponse response = execute(url, SdkHttpMethod.GET, param, headers, null, DEFAULT_TIME_OUT);
if (response == null) {
throw new StorageException("request get has no response");
}
AbortableInputStream abortableInputStream = response.content().orElse(null);
try {
return abortableInputStream != null ? IoUtils.toUtf8String(abortableInputStream) : null;
} catch (IOException e) {
throw new StorageException(ExceptionUtils.toString(e));
}
}
use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class AbstractS3Client method getObject.
@Override
public StorageFileInfo getObject(String key) {
key = formatKey(key, false);
MinioClient minioClient = getClient(key, "getObject");
try {
StatObjectResponse response = minioClient.statObject(StatObjectArgs.builder().bucket(config.getBucketName()).object(key).build());
StorageFileInfo storageFileInfo = new StorageFileInfo();
storageFileInfo.setBucketName(response.bucket());
storageFileInfo.setKey(key);
storageFileInfo.setHost(formatHost());
storageFileInfo.setSize(response.size());
storageFileInfo.setLastModified(DateUtils.getMillis(response.lastModified().toLocalDateTime()));
Map<String, Object> userMeta = new HashMap<>();
userMeta.putAll(response.userMetadata());
storageFileInfo.setMetaData(userMeta);
storageFileInfo.setETag(response.etag());
return storageFileInfo;
} catch (ErrorResponseException e) {
throw throwS3Exception(e);
} catch (Exception e) {
throw new StorageException("0002", ExceptionUtils.toShortString(e, 2));
}
}
use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class AbstractS3Client method putObjectCommon.
StorageFileInfo putObjectCommon(String key, Object in, String contentType, Map<String, String> userMetaData, Consumer<StorageProgressEvent> consumer) {
key = formatKey(key, false);
MinioClient minioClient = getClient(key, "putObject");
InputStream inputStream = null;
try {
PutObjectArgs.Builder builder = PutObjectArgs.builder().bucket(config.getBucketName()).object(key);
if (in instanceof File) {
inputStream = new FileInputStream((File) in);
} else if (in instanceof InputStream) {
// 根据文件名称 放入objectMetaData
inputStream = (InputStream) in;
} else if (in instanceof byte[]) {
inputStream = new ByteArrayInputStream((byte[]) in);
}
builder.stream(inputStream, inputStream.available(), -1);
if (StringUtils.isBlank(contentType)) {
contentType = StorageUtil.getMimeType(key);
}
if (StringUtils.isNotBlank(contentType)) {
builder.contentType(contentType);
}
if (userMetaData == null) {
userMetaData = new HashMap<>(1);
}
userMetaData.put("upclient", "storage");
builder.userMetadata(userMetaData);
ObjectWriteResponse objectWriteResponse = minioClient.putObject(builder.build());
StorageFileInfo fileInfo = new StorageFileInfo();
fileInfo.setBucketName(config.getBucketName());
fileInfo.setKey(objectWriteResponse.object());
fileInfo.setETag(objectWriteResponse.etag());
fileInfo.setHost(formatHost());
return fileInfo;
} catch (ErrorResponseException e) {
throw throwS3Exception(e);
} catch (Exception e) {
throw new StorageException("0002", ExceptionUtils.toShortString(e, 2));
} finally {
StreamUtils.close(inputStream);
}
}
use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class AbstractS3Client method copyObject.
@Override
public StorageFileInfo copyObject(String sourceKeyWithoutBasePath, String destinationKeyWithoutBasePath, Map<String, String> userMetaData) {
MinioClient minioClient = getClient(sourceKeyWithoutBasePath, "copyObject");
try {
if (userMetaData == null) {
userMetaData = new HashMap<>(1);
}
userMetaData.put("upclient", "storage");
CopyObjectArgs copyObjectArgs = CopyObjectArgs.builder().bucket(config.getBucketName()).object(destinationKeyWithoutBasePath).userMetadata(userMetaData).source(CopySource.builder().bucket(config.getBucketName()).object(sourceKeyWithoutBasePath).build()).build();
ObjectWriteResponse response = minioClient.copyObject(copyObjectArgs);
StorageFileInfo fileInfo = new StorageFileInfo();
fileInfo.setBucketName(config.getBucketName());
fileInfo.setKey(response.object());
fileInfo.setETag(response.etag());
fileInfo.setHost(formatHost());
return fileInfo;
} catch (ErrorResponseException e) {
throw throwS3Exception(e);
} catch (Exception e) {
throw new StorageException("0002", ExceptionUtils.toShortString(e, 2));
}
}
use of com.workoss.boot.storage.exception.StorageException in project boot by workoss.
the class AbstractS3Client method deleteObject.
@Override
public void deleteObject(String key) {
key = formatKey(key, false);
MinioClient minioClient = getClient(key, "deleteObject");
try {
minioClient.removeObject(RemoveObjectArgs.builder().bucket(config.getBucketName()).object(key).build());
} catch (ErrorResponseException e) {
throw throwS3Exception(e);
} catch (Exception e) {
throw new StorageException("0002", ExceptionUtils.toShortString(e, 2));
}
}
Aggregations