RED-6864 - Add fileProxyStreamForDownload

This commit is contained in:
Andrei Isvoran 2023-08-10 17:01:09 +03:00
parent bf3a790e7b
commit 6bc744dcce

View File

@ -4,6 +4,7 @@ import static com.iqser.red.service.persistence.management.v1.processor.roles.Ac
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_DOWNLOAD_STATUS;
import static com.iqser.red.service.persistence.management.v1.processor.utils.DownloadBufferUtils.fileProxyStreamForDownload;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -209,8 +210,9 @@ public class DownloadController implements DownloadResource {
TenantContext.setTenantId(tenantId);
var downloadStatus = getDownloadStatus(storageId, userId);
var fileDownloadStream = getFileForDownload(storageId, userId);
fileProxyStreamForDownload(fileDownloadStream);
return getResponseEntity(inline, fileDownloadStream, downloadStatus.getFilename(), MediaType.parseMediaType("application/zip"), downloadStatus.getFileSize());
return getResponseEntity(inline, new InputStreamResource(fileDownloadStream), downloadStatus.getFilename(), MediaType.parseMediaType("application/zip"), downloadStatus.getFileSize());
});
}
@ -224,7 +226,7 @@ public class DownloadController implements DownloadResource {
}
private InputStreamResource getFileForDownload(String storageId, String userId) {
private InputStream getFileForDownload(String storageId, String userId) {
try {
var response = fileManagementStorageService.getObject(TenantContext.getTenantId(), storageId);
@ -237,7 +239,7 @@ public class DownloadController implements DownloadResource {
.build());
downloadService.setDownloaded(JSONPrimitive.of(storageId));
return new InputStreamResource(response);
return response;
} catch (Exception e) {
throw new NotFoundException(e.getMessage(), e);
}
@ -279,10 +281,11 @@ public class DownloadController implements DownloadResource {
var token = oneTimeTokenDownloadService.getToken(oneTimeToken);
var downloadStatus = getDownloadStatus(token.getStorageId(), token.getUserId());
var fileDownloadStream = getFileForDownload(token.getStorageId(), token.getUserId());
fileProxyStreamForDownload(fileDownloadStream);
TenantContext.clear();
return getResponseEntity(inline, fileDownloadStream, downloadStatus.getFilename(), MediaType.parseMediaType("application/zip"), downloadStatus.getFileSize());
return getResponseEntity(inline, new InputStreamResource((fileDownloadStream)), downloadStatus.getFilename(), MediaType.parseMediaType("application/zip"), downloadStatus.getFileSize());
});
}