fix: 업로드 이미지 URL 을 절대경로로 반환 — 앱(Capacitor)에서 이미지 표시
CI / build (push) Failing after 15m22s

- 앱은 출처가 localhost 라 /api/images/{id} 상대경로가 백엔드로 안 감 → 안 보임
- app.public-url(기본 https://app.sblog.kr) 기준 절대 URL 반환 → 웹/PC/APK 모두 로드

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ByungCheol
2026-06-07 20:32:37 +09:00
parent f9abd0c989
commit 55c47a43e6
2 changed files with 9 additions and 1 deletions
@@ -6,6 +6,7 @@ import com.sb.web.board.domain.BoardImage;
import com.sb.web.board.service.BoardImageService; import com.sb.web.board.service.BoardImageService;
import com.sb.web.common.exception.ApiException; import com.sb.web.common.exception.ApiException;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.CacheControl; import org.springframework.http.CacheControl;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@@ -28,6 +29,10 @@ public class BoardImageController {
private final BoardImageService service; private final BoardImageService service;
// 앱(Capacitor) 출처가 localhost 라 상대경로가 안 통하므로 절대 URL 로 반환
@Value("${app.public-url:}")
private String publicUrl;
@PostMapping("/api/board/images") @PostMapping("/api/board/images")
public Map<String, String> upload( public Map<String, String> upload(
@RequestParam("image") MultipartFile file, @RequestParam("image") MultipartFile file,
@@ -40,7 +45,8 @@ public class BoardImageController {
throw new ApiException(HttpStatus.BAD_REQUEST, "이미지 파일만 업로드할 수 있습니다."); throw new ApiException(HttpStatus.BAD_REQUEST, "이미지 파일만 업로드할 수 있습니다.");
} }
Long id = service.save(current.getId(), contentType, file.getBytes()); Long id = service.save(current.getId(), contentType, file.getBytes());
return Map.of("url", "/api/images/" + id); String base = (publicUrl == null) ? "" : publicUrl.replaceAll("/+$", "");
return Map.of("url", base + "/api/images/" + id);
} }
@GetMapping("/api/images/{id}") @GetMapping("/api/images/{id}")
+2
View File
@@ -74,6 +74,8 @@ google:
app: app:
crypto: crypto:
account-key: ${ACCOUNT_CRYPTO_KEY:} account-key: ${ACCOUNT_CRYPTO_KEY:}
# 업로드 이미지 등 외부에서 접근할 절대 URL 베이스. 앱(Capacitor)은 출처가 localhost 라 상대경로가 안 통함.
public-url: ${PUBLIC_URL:https://app.sblog.kr}
# ===== Logging ===== # ===== Logging =====
logging: logging: