mirror of
https://github.com/headporter81/specialsource-homepage-backend.git
synced 2026-08-08 15:41:11 +09:00
This commit is contained in:
@@ -18,25 +18,29 @@ public class FileSyncController {
|
||||
HttpServletRequest request,
|
||||
@RequestParam(value = "filename", required = false) String originalFileName) {
|
||||
|
||||
// 🟢 디버깅용 로그: MacroDroid가 주소창에 무엇을 실어서 보냈는지 포착합니다.
|
||||
System.out.println("🔗 전체 쿼리 스트링: " + request.getQueryString());
|
||||
System.out.println("📂 수신된 파일명 변수값: " + originalFileName);
|
||||
|
||||
try {
|
||||
// 1. 🟢 파일명 검증: 원래 명칭이 비어있거나 누락되었다면 요청을 거부합니다.
|
||||
if (originalFileName == null || originalFileName.trim().isEmpty()) {
|
||||
return ResponseEntity.badRequest().body("Error: 원래 파일명이 전달되지 않았습니다.");
|
||||
String fileName = originalFileName;
|
||||
|
||||
// 🟢 파일명이 누락되었을 때 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/";
|
||||
File uploadDir = new File(uploadDirPath);
|
||||
|
||||
// 디렉토리가 없으면 안전하게 자동 생성
|
||||
if (!uploadDir.exists()) {
|
||||
uploadDir.mkdirs();
|
||||
}
|
||||
|
||||
// 3. 🟢 파일명 가공 없이 원래 명칭 그대로 저장 파일 객체 정의
|
||||
File targetFile = new File(uploadDir, originalFileName);
|
||||
File targetFile = new File(uploadDir, fileName);
|
||||
|
||||
// 4. 바이너리 스트림을 읽어 파일 작성 진행
|
||||
// 파일 저장 진행
|
||||
try (InputStream is = request.getInputStream();
|
||||
FileOutputStream fos = new FileOutputStream(targetFile)) {
|
||||
|
||||
@@ -47,8 +51,8 @@ public class FileSyncController {
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("✅ 원래 명칭 그대로 업로드 완료: " + targetFile.getAbsolutePath());
|
||||
return ResponseEntity.ok("Upload Success: " + originalFileName);
|
||||
System.out.println("✅ 파일 처리 완료: " + targetFile.getAbsolutePath());
|
||||
return ResponseEntity.ok("Upload Processed: " + fileName);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user