This commit is contained in:
@@ -7,6 +7,7 @@ import com.vrt.fileprotection.audio.AudioCheckResult;
|
||||
import com.vrt.fileprotection.documents.DocumentCheckResult;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -163,7 +164,7 @@ public class ApiController {
|
||||
}
|
||||
|
||||
@GetMapping("/internal/data-download/{fileId}")
|
||||
public ResponseEntity<Resource> getPublicFile(@PathVariable String fileId) {
|
||||
public ResponseEntity<byte[]> getPublicFile(@PathVariable String fileId) {
|
||||
try {
|
||||
FileEntity fileEntity = fileEntityRepository.findById(fileId)
|
||||
.orElseThrow(() -> new FileNotFoundException("Not found in DB: " + fileId));
|
||||
@@ -174,14 +175,17 @@ public class ApiController {
|
||||
.filename(fileEntity.getOriginalFileName(), StandardCharsets.UTF_8)
|
||||
.build();
|
||||
|
||||
InputStream inputStream = cloudStorageService.readFileFromStorage(fileEntity.getFilePath());
|
||||
InputStreamResource resource = new InputStreamResource(inputStream);
|
||||
byte[] fileBytes;
|
||||
try (InputStream inputStream = cloudStorageService.readFileFromStorage(fileEntity.getFilePath())) {
|
||||
fileBytes = IOUtils.toByteArray(inputStream);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(mediaType)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition.toString())
|
||||
.header(HttpHeaders.CACHE_CONTROL, "public, max-age=3600")
|
||||
.body(resource);
|
||||
.body(fileBytes);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
log.warn("File not found in DB: {}", fileId);
|
||||
return ResponseEntity.notFound().build();
|
||||
|
||||
Reference in New Issue
Block a user