|
|
@@ -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}")
|
|
|
|