use of com.workoss.boot.storage.exception.StorageDownloadException in project boot by workoss.
the class AbstractS3Client method download.
@Override
public File download(String key, File destFile, Consumer<StorageProgressEvent> consumer) {
key = formatKey(key, false);
MinioClient minioClient = getClient(key, "downloadObject");
try {
minioClient.downloadObject(DownloadObjectArgs.builder().bucket(config.getBucketName()).object(key).filename(destFile.getPath()).build());
return destFile;
} catch (ErrorResponseException e) {
throw throwS3Exception(e);
} catch (Exception e) {
throw new StorageDownloadException("0002", ExceptionUtils.toShortString(e, 2));
}
}
use of com.workoss.boot.storage.exception.StorageDownloadException in project boot by workoss.
the class AbstractS3Client method download.
@Override
public byte[] download(String key, Consumer<StorageProgressEvent> consumer) {
key = formatKey(key, false);
try (S3AsyncClient s3AsyncClient = getClient(key, "downloadObject")) {
GetObjectRequest getObjectRequest = GetObjectRequest.builder().bucket(config.getBucketName()).key(key).build();
ResponseBytes<GetObjectResponse> getObjectResponseResponseBytes = s3AsyncClient.getObject(getObjectRequest, AsyncResponseTransformer.toBytes()).get();
return getObjectResponseResponseBytes.asByteArray();
} catch (S3Exception s3Exception) {
throw throwS3Exception(s3Exception);
} catch (Exception e) {
throw new StorageDownloadException("0002", e);
}
}
use of com.workoss.boot.storage.exception.StorageDownloadException in project boot by workoss.
the class AbstractS3Client method downloadStream.
@Override
public StorageFileInfo downloadStream(String key, Consumer<StorageProgressEvent> consumer) {
key = formatKey(key, false);
MinioClient minioClient = getClient(key, "downloadObject");
try {
GetObjectResponse objectResponse = minioClient.getObject(GetObjectArgs.builder().bucket(config.getBucketName()).object(key).build());
StorageFileInfo storageFileInfo = new StorageFileInfo().setBucketName(config.getBucketName()).setKey(key).setHost(formatHost()).setContent(objectResponse);
Headers headers = objectResponse.headers();
if (headers != null && headers.toMultimap() != null) {
Map<String, Object> metadata = headers.toMultimap().entrySet().stream().map(stringListEntry -> {
List<String> value = stringListEntry.getValue();
if (value != null && value.size() >= 1) {
return Pair.of(stringListEntry.getKey(), value.get(0));
}
return Pair.of(stringListEntry.getKey(), null);
}).collect(Collectors.toMap(Pair::getFirst, Pair::getSecond));
storageFileInfo.setMetaData(metadata);
}
return storageFileInfo;
} catch (ErrorResponseException e) {
throw throwS3Exception(e);
} catch (Exception e) {
throw new StorageDownloadException("0002", ExceptionUtils.toShortString(e, 2));
}
}
Aggregations