RED-6864 - Optimization of Upload and Download for Large Files in Azure Blob Storage and AWS S3/MinIO

update to the new version for storage-commons
replace getObject from storageService with downloadTo
update tests
This commit is contained in:
Corina Olariu 2023-08-08 20:00:28 +03:00
parent 0691cec892
commit efad7fa66a
3 changed files with 26 additions and 4 deletions

View File

@ -33,7 +33,7 @@
<dependency>
<groupId>com.iqser.red</groupId>
<artifactId>platform-commons-dependency</artifactId>
<version>2.6.0</version>
<version>2.7.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@ -1,6 +1,8 @@
package com.iqser.red.service.redaction.report.v1.server.storage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
@ -43,7 +45,7 @@ public class ReportStorageService {
public byte[] getReportTemplate(String storageId) {
try {
return IOUtils.toByteArray(storageService.getObject(TenantContext.getTenantId(), storageId).getInputStream());
return IOUtils.toByteArray(getObject(TenantContext.getTenantId(), storageId));
} catch (IOException e) {
throw new RuntimeException("Could not get report template.");
}
@ -53,7 +55,7 @@ public class ReportStorageService {
@SneakyThrows
public byte[] getStoredObjectBytes(String dossierId, String fileId, FileType fileType) {
return IOUtils.toByteArray(storageService.getObject(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, fileType)).getInputStream());
return IOUtils.toByteArray(getObject(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, fileType)));
}
@ -62,4 +64,12 @@ public class ReportStorageService {
return storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, fileType));
}
@SneakyThrows
public FileInputStream getObject(String tenantId, String storageId) {
File destFile = File.createTempFile("destFile", ".data");
destFile.deleteOnExit();
storageService.downloadTo(tenantId, storageId, destFile);
return new FileInputStream(destFile);
}
}

View File

@ -31,7 +31,6 @@ public class FileSystemBackedStorageService implements StorageService {
@SneakyThrows
@Override
public InputStreamResource getObject(String tenantId, String objectId) {
var res = dataMap.get(objectId);
@ -42,6 +41,18 @@ public class FileSystemBackedStorageService implements StorageService {
}
@SneakyThrows
@Override
public void downloadTo(String tenantId, String objectId, File destinationFile) {
var res = dataMap.get(objectId);
if (res == null) {
throw new StorageObjectDoesNotExist(new RuntimeException());
}
IOUtils.copy(new FileInputStream(res), new FileOutputStream(destinationFile));
}
@Override
public void deleteObject(String tenantId, String objectId) {
@ -118,4 +129,5 @@ public class FileSystemBackedStorageService implements StorageService {
this.dataMap.clear();
}
}