fix - 파일 업로드 수정
SpecialSource Backend CI/CD / build-and-deploy (push) Successful in 55s

This commit is contained in:
sungjin.choi
2026-07-20 16:31:03 +09:00
parent 0536a7fd89
commit 4a022a4202
@@ -18,25 +18,29 @@ public class FileSyncController {
HttpServletRequest request, HttpServletRequest request,
@RequestParam(value = "filename", required = false) String originalFileName) { @RequestParam(value = "filename", required = false) String originalFileName) {
// 🟢 디버깅용 로그: MacroDroid가 주소창에 무엇을 실어서 보냈는지 포착합니다.
System.out.println("🔗 전체 쿼리 스트링: " + request.getQueryString());
System.out.println("📂 수신된 파일명 변수값: " + originalFileName);
try { try {
// 1. 🟢 파일명 검증: 원래 명칭이 비어있거나 누락되었다면 요청을 거부합니다. String fileName = originalFileName;
if (originalFileName == null || originalFileName.trim().isEmpty()) {
return ResponseEntity.badRequest().body("Error: 원래 파일명이 전달되지 않았습니다."); // 🟢 파일명이 누락되었을 때 400 에러로 터뜨리지 않고, 무엇이 잘못되었는지 로그를 남긴 후 임시 저장합니다.
if (fileName == null || fileName.trim().isEmpty()) {
System.out.println("⚠️ 경고: MacroDroid에서 filename 파라미터가 빈 값으로 전송되었습니다.");
fileName = "missing_name_" + System.currentTimeMillis() + ".dat";
} }
// 2. 유저님이 지정하신 나스 실제 절대 경로 // 나스 실제 절대 경로
String uploadDirPath = "/volume1/docker/upload_dir/"; String uploadDirPath = "/volume1/docker/upload_dir/";
File uploadDir = new File(uploadDirPath); File uploadDir = new File(uploadDirPath);
// 디렉토리가 없으면 안전하게 자동 생성
if (!uploadDir.exists()) { if (!uploadDir.exists()) {
uploadDir.mkdirs(); uploadDir.mkdirs();
} }
// 3. 🟢 파일명 가공 없이 원래 명칭 그대로 저장 파일 객체 정의 File targetFile = new File(uploadDir, fileName);
File targetFile = new File(uploadDir, originalFileName);
// 4. 바이너리 스트림을 읽어 파일 작성 진행 // 파일 저장 진행
try (InputStream is = request.getInputStream(); try (InputStream is = request.getInputStream();
FileOutputStream fos = new FileOutputStream(targetFile)) { FileOutputStream fos = new FileOutputStream(targetFile)) {
@@ -47,8 +51,8 @@ public class FileSyncController {
} }
} }
System.out.println("원래 명칭 그대로 업로드 완료: " + targetFile.getAbsolutePath()); System.out.println("파일 처리 완료: " + targetFile.getAbsolutePath());
return ResponseEntity.ok("Upload Success: " + originalFileName); return ResponseEntity.ok("Upload Processed: " + fileName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();