업로드 관련 수정
This commit is contained in:
@@ -59,17 +59,17 @@ public class UploadService {
|
||||
UploadDto.UploadRes upRes = new UploadDto.UploadRes();
|
||||
|
||||
long datasetId = 0;
|
||||
if( upAddReqDto.getDatasetId() != null )datasetId = upAddReqDto.getDatasetId();
|
||||
String uploadId = System.currentTimeMillis()+"";
|
||||
//UUID uuid = UUID.randomUUID();
|
||||
if (upAddReqDto.getDatasetId() != null) datasetId = upAddReqDto.getDatasetId();
|
||||
String uploadId = System.currentTimeMillis() + "";
|
||||
// UUID uuid = UUID.randomUUID();
|
||||
UUID uuid = upAddReqDto.getUuid();
|
||||
String tmpDataSetDir = upAddReqDto.getTempPath()+uuid;
|
||||
String fianlDir = upAddReqDto.getFinalPath()+uuid;
|
||||
String tmpDataSetDir = upAddReqDto.getTempPath() + uuid;
|
||||
String fianlDir = upAddReqDto.getFinalPath() + uuid;
|
||||
String uploadDivi = upAddReqDto.getUploadDivi();
|
||||
//String fileName = file.getOriginalFilename();
|
||||
// String fileName = file.getOriginalFilename();
|
||||
String fileName = upAddReqDto.getFileName();
|
||||
Integer chunkIndex = upAddReqDto.getChunkIndex();
|
||||
Integer chunkTotalIndex = upAddReqDto.getChunkTotalIndex();
|
||||
Integer chunkTotalIndex = upAddReqDto.getChunkTotalIndex();
|
||||
String status = FileUploadStatus.INIT.name();
|
||||
|
||||
upRes.setUuid(uuid);
|
||||
@@ -83,37 +83,33 @@ public class UploadService {
|
||||
upAddReqDto.setTempPath(tmpDataSetDir);
|
||||
upAddReqDto.setFinalPath(fianlDir);
|
||||
|
||||
//세션 신규,중복체크(초기화 포함)
|
||||
// 세션 신규,중복체크(초기화 포함)
|
||||
UploadDto.uploadDto dto = this.checkUploadSession(upAddReqDto, upRes);
|
||||
if( !upRes.getRes().equals("success") )return upRes;
|
||||
|
||||
if (!upRes.getRes().equals("success")) return upRes;
|
||||
|
||||
status = FileUploadStatus.UPLOADING.name();
|
||||
upAddReqDto.setStatus(status);
|
||||
|
||||
if( dto != null )
|
||||
{
|
||||
tmpDataSetDir = dto.getTempPath();
|
||||
if (dto != null) {
|
||||
tmpDataSetDir = dto.getTempPath();
|
||||
fianlDir = dto.getFinalPath();
|
||||
}
|
||||
|
||||
//폴더 생성 및 체크
|
||||
if( ! checkChunkFoler(upRes, tmpDataSetDir, fianlDir) )return upRes;
|
||||
// 폴더 생성 및 체크
|
||||
if (!checkChunkFoler(upRes, tmpDataSetDir, fianlDir)) return upRes;
|
||||
|
||||
//chunk저장하기
|
||||
if( ! FIleChecker.multipartChunkSaveTo(file, tmpDataSetDir, chunkIndex ) )
|
||||
{
|
||||
// chunk저장하기
|
||||
if (!FIleChecker.multipartChunkSaveTo(file, tmpDataSetDir, chunkIndex)) {
|
||||
upRes.setRes("fail");
|
||||
upRes.setResMsg("chunkIndex:"+chunkIndex+" 업로드 애러");
|
||||
upRes.setResMsg("chunkIndex:" + chunkIndex + " 업로드 애러");
|
||||
}
|
||||
|
||||
if( chunkIndex == chunkTotalIndex ) {
|
||||
if (chunkIndex == chunkTotalIndex) {
|
||||
|
||||
upAddReqDto.setUploadId(dto.getUploadId());
|
||||
upAddReqDto.setStatus(FileUploadStatus.DONE.name());
|
||||
uploadSessionCoreService.updateUploadSessionStatus(upAddReqDto);
|
||||
|
||||
|
||||
try {
|
||||
this.mergeChunks(tmpDataSetDir, fianlDir, fileName, chunkTotalIndex);
|
||||
|
||||
@@ -122,14 +118,11 @@ public class UploadService {
|
||||
uploadSessionCoreService.updateUploadSessionStatus(upAddReqDto);
|
||||
|
||||
} catch (IOException e) {
|
||||
//throw new RuntimeException(e);
|
||||
// throw new RuntimeException(e);
|
||||
upRes.setRes("fail");
|
||||
upRes.setResMsg("파일Chunk 병합(merge) 애러");
|
||||
return upRes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return upRes;
|
||||
@@ -149,7 +142,8 @@ public class UploadService {
|
||||
upRes.setChunkTotalIndex(dto.getChunkTotalIndex());
|
||||
|
||||
try {
|
||||
this.mergeChunks(dto.getTempPath(), dto.getFinalPath(), dto.getFileName(), dto.getChunkTotalIndex());
|
||||
this.mergeChunks(
|
||||
dto.getTempPath(), dto.getFinalPath(), dto.getFileName(), dto.getChunkTotalIndex());
|
||||
} catch (IOException e) {
|
||||
|
||||
upRes.setRes("fail");
|
||||
@@ -159,21 +153,17 @@ public class UploadService {
|
||||
}
|
||||
|
||||
return upRes;
|
||||
|
||||
}
|
||||
|
||||
public boolean checkChunkFoler(UploadDto.UploadRes upRes, String tmpDataSetDir, String fianlDir)
|
||||
{
|
||||
public boolean checkChunkFoler(UploadDto.UploadRes upRes, String tmpDataSetDir, String fianlDir) {
|
||||
|
||||
if( ! FIleChecker.mkDir(tmpDataSetDir) )
|
||||
{
|
||||
if (!FIleChecker.mkDir(tmpDataSetDir)) {
|
||||
upRes.setRes("fail");
|
||||
upRes.setRes("CHUNK 폴더 생성 ERROR");
|
||||
return false;
|
||||
}
|
||||
|
||||
if( ! FIleChecker.mkDir(fianlDir) )
|
||||
{
|
||||
if (!FIleChecker.mkDir(fianlDir)) {
|
||||
upRes.setRes("fail");
|
||||
upRes.setRes("업로드 완료 폴더 생성 ERROR");
|
||||
return false;
|
||||
@@ -182,28 +172,26 @@ public class UploadService {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public UploadDto.uploadDto checkUploadSession(UploadDto.UploadAddReq upAddReqDto, UploadDto.UploadRes upRes) {
|
||||
public UploadDto.uploadDto checkUploadSession(
|
||||
UploadDto.UploadAddReq upAddReqDto, UploadDto.UploadRes upRes) {
|
||||
|
||||
upRes.setRes("success");
|
||||
upRes.setResMsg("정상처리되었습니다.");
|
||||
|
||||
UploadDto.uploadDto dto = uploadSessionCoreService.findByUuid(upAddReqDto.getUuid());
|
||||
|
||||
if( upAddReqDto.getChunkIndex() == 0 ) {
|
||||
if( dto != null )
|
||||
{
|
||||
if (upAddReqDto.getChunkIndex() == 0) {
|
||||
if (dto != null) {
|
||||
upRes.setRes("duplicate");
|
||||
upRes.setResMsg("이미 진행중인 업로드세션입니다.");
|
||||
return dto;
|
||||
}
|
||||
|
||||
upAddReqDto.setStatus("UPLOADING");
|
||||
upRes.setUuid( upAddReqDto.getUuid() );
|
||||
upRes.setUuid(upAddReqDto.getUuid());
|
||||
uploadSessionCoreService.createUploadSession(upAddReqDto);
|
||||
}
|
||||
else {
|
||||
if( dto == null ){
|
||||
} else {
|
||||
if (dto == null) {
|
||||
upRes.setRes("nosession");
|
||||
upRes.setResMsg("업로드 세션이 존재하지 않습니다.");
|
||||
return dto;
|
||||
@@ -214,22 +202,22 @@ public class UploadService {
|
||||
uploadSessionCoreService.updateUploadSessionStatus(upAddReqDto);
|
||||
}
|
||||
|
||||
if( dto != null )upRes.setUuid( dto.getUuid() );
|
||||
if (dto != null) upRes.setUuid(dto.getUuid());
|
||||
|
||||
upRes.setChunkIndex(upAddReqDto.getChunkIndex());
|
||||
upRes.setChunkTotalIndex(upAddReqDto.getChunkTotalIndex());
|
||||
|
||||
|
||||
return dto;
|
||||
|
||||
}
|
||||
|
||||
public void mergeChunks(String tmpDir, String fianlDir, String fileName, int chunkTotalIndex) throws IOException {
|
||||
public void mergeChunks(String tmpDir, String fianlDir, String fileName, int chunkTotalIndex)
|
||||
throws IOException {
|
||||
|
||||
Path outputPath = Paths.get(fianlDir, fileName);
|
||||
try (FileChannel outChannel = FileChannel.open(outputPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
|
||||
try (FileChannel outChannel =
|
||||
FileChannel.open(outputPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
|
||||
for (int i = 0; i <= chunkTotalIndex; i++) {
|
||||
Path chunkPath = Paths.get(tmpDir, i+"");
|
||||
Path chunkPath = Paths.get(tmpDir, i + "");
|
||||
|
||||
try (FileChannel inChannel = FileChannel.open(chunkPath, StandardOpenOption.READ)) {
|
||||
long transferred = 0;
|
||||
@@ -243,10 +231,7 @@ public class UploadService {
|
||||
}
|
||||
}
|
||||
|
||||
//병합후 임시 폴더 삭제
|
||||
// 병합후 임시 폴더 삭제
|
||||
FIleChecker.deleteFolder(tmpDir);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user