From 123b21cab2f35c75d17d2396a234f40cb5364501 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 2 Jan 2024 06:27:58 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BF=A0=ED=8F=B0=20=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EB=8B=A4=EC=9A=B4=EB=A1=9C=EB=93=9C=20API=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20-=20MediaType=20openxmlformats=20=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../can/coupon/CanCouponController.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/coupon/CanCouponController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/coupon/CanCouponController.kt index 219996f..c67c4f7 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/coupon/CanCouponController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/coupon/CanCouponController.kt @@ -3,6 +3,7 @@ package kr.co.vividnext.sodalive.can.coupon import kr.co.vividnext.sodalive.common.ApiResponse import kr.co.vividnext.sodalive.common.SodaException import kr.co.vividnext.sodalive.member.Member +import org.springframework.core.io.InputStreamResource import org.springframework.data.domain.Pageable import org.springframework.http.HttpHeaders import org.springframework.http.MediaType @@ -15,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController +import java.net.URLEncoder +import java.nio.charset.StandardCharsets @RestController @RequestMapping("/can/coupon") @@ -68,10 +71,22 @@ class CanCouponController(private val service: CanCouponService) { if (member == null) throw SodaException("로그인 정보를 확인해주세요.") val fileName = "쿠폰번호리스트.xlsx" + val encodedFileName = URLEncoder.encode( + fileName, + StandardCharsets.UTF_8.toString() + ).replace("+", "%20") + val contentDisposition = "attachment; filename*=UTF-8''$encodedFileName" + val headers = HttpHeaders().apply { + add(HttpHeaders.CONTENT_DISPOSITION, contentDisposition) + } + val response = service.downloadCouponNumberList(couponId) ResponseEntity.ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "attatchment;filename=$fileName") - .contentType(MediaType.parseMediaType("application/vnd.ms-excel")) - .body(response) + .headers(headers) + .contentType( + MediaType + .parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") + ) + .body(InputStreamResource(response)) } }