postman์ผ๋ก ํ์ผ ์ ์ก ํ ์คํธ(Rest API) ๐
postman์ ์ด์ฉํด์ ์คํ๋ง ํ์ผ ์ ๋ก๋ ํ ์คํธํ๋ ๋ฐฉ๋ฒ์ ์๊ฒ๋์ด ๊ธฐ๋กํ๋ค.
๊ทธ๋์์ html์ผ๋ก form์ ๋ง๋ค์ด์ ํ์๋๋ฐ.. ๐
๋ฐฉ๋ฒ์ ์์ฃผ ์ฝ๋ค.
๋น์ฐํ ์ ์ก๋ฐฉ์์ POST๋ก ์ ํ
Body > form-data > key > File๋ก ์ ํ > value์ Select Files ์ ํ ์ ํ์ผ ์ ๋ก๋๊ฐ ๊ฐ๋ฅํ๋ค.
์ค์ ๋ก ์๋ฒ์์ ์ ๋ฐ์์ง๋์ง ํ ์คํธ๋ฅผ ํด๋ณด๊ฒ ๋ค.
์ปจํธ๋กค๋ฌ ์์ฑ ํ ๋ก๊ทธ๋ฅผ ์ฐ์ด์ ์ ๋ค์ด์ค๋์ง๋ง ํ์ธ ํด๋ณด๊ฒ ๋ค.
controller
package study.lsyrestapitest1.controller.api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping(value = "/v1/file")
public class FileController {
@PostMapping(value = "upload")
public Object upload(@RequestParam(value = "file") MultipartFile file) throws Exception {
log.info("file => {}", file.getOriginalFilename());
return "์ฑ๊ณต์ด๋ค.";
}
}
ํ ์คํธ ๊ฒฐ๊ณผ
์ปจํธ๋กค๋ฌ์์ ํ์ผ ์ด๋ฆ๋ง ์ฐ์ด๋ดค๋๋ฐ ์ ์ฐํ๋ค.
postman์์ ์๋ฒ๋ก ํ์ผ ์ ์ก์ด ์ฃผ ๋ชฉ์ ์ด๋ผ ์ค์ ํ์ผ ์ ๋ก๋ ๋ก์ง์ ์๋ตํ๋ค.
postman์ ์ด์ฉํด์ ํ์ผ ์ ๋ก๋ ํ ์คํธ๋ฅผ ํ๋ฉด html ํ๋ฉด์ ์ง์ ๋ง๋๋ ๋ฒ๊ฑฐ๋ก์์ ์ค์ผ ์ ์๊ฒ ๋ค.

๋๊ธ