대용량 다운로드 수정

This commit is contained in:
2026-02-11 12:34:51 +09:00
parent 4cbd2b8d76
commit 5b09b2e29a
5 changed files with 21 additions and 78 deletions

View File

@@ -1,6 +1,5 @@
package com.kamco.cd.kamcoback.label;
import com.kamco.cd.kamcoback.common.download.DownloadExecutor;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.InferenceDetail;
@@ -31,6 +30,7 @@ import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.coyote.BadRequestException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.data.domain.Page;
@@ -53,7 +53,6 @@ import org.springframework.web.bind.annotation.RestController;
public class LabelAllocateApiController {
private final LabelAllocateService labelAllocateService;
private final DownloadExecutor downloadExecutor;
@Value("${file.dataset-response}")
private String responsePath;
@@ -386,25 +385,22 @@ public class LabelAllocateApiController {
@Parameter(example = "6d8d49dc-0c9d-4124-adc7-b9ca610cc394") @PathVariable UUID uuid)
throws IOException {
// if (!labelAllocateService.isDownloadable(uuid)) {
// throw new BadRequestException();
// }
if (!labelAllocateService.isDownloadable(uuid)) {
throw new BadRequestException();
}
String uid = labelAllocateService.findLearnUid(uuid);
Path zipPath = Paths.get(responsePath).resolve(uid + ".zip");
long size = Files.size(zipPath);
Resource resource = new org.springframework.core.io.UrlResource(zipPath.toUri());
return ResponseEntity.ok()
.header(
HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"" + zipPath.getFileName().toString() + "\"")
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + uid + ".zip" + "\"")
.header(HttpHeaders.ACCEPT_RANGES, "bytes")
.header("X-Accel-Buffering", "no") // nginx/ingress 버퍼링 방지 힌트
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.contentLength(size)
.body(resource);
// return downloadExecutor.stream(
// new DownloadSpec(uuid, zipPath, uid + ".zip", MediaType.APPLICATION_OCTET_STREAM));
}
@Operation(summary = "라벨 파일 다운로드 이력 조회", description = "라벨 파일 다운로드 이력 조회")