Swagger
에서 테스트를 못해요. Postman
에서 해주세요.
postman
에서 헤더에 토큰 설정하는 방법
프론트 쪽에서.... 이렇게 하는 게 맞는지 모르겠지만....
file은 form-data로 기본정보는 request로 담아 application/json
donationSave :
function () {
var data = {
title: ---,
content: ---,
category: ---,
quality: ---,
tags: []
};
var form =$('#form')[0];
var formData = new FormData(form);
formData.append('file', #파일리스트);
formData.append('request',
new Blob([JSON.stringify(data)],
{type: "application/json"}));
$.ajax({
type: 'POST',
url: '/donations',
processData: false,
contentType:false,
data: formData,
}).done(function() {
alert('글이 등록되었습니다.');
window.location.href = '/';
}).fail(function (error) {
alert(JSON.stringify(error));
});
}
POST
/donations → 회원만 접근가능
요청 값
// HTTP
POST /donations HTTP/1.1
Host: localhost:8080
Authorization: Bearer 로그인 후 발급된 토큰
Content-Length: 537
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="rabbit.png"
Content-Type: image/png
(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="mask.png"
Content-Type: image/png
(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="request"
Content-Type: application/json
{
"category":"재능기부",
"content": "기부할래요",
"quality": "나쁨",
"tags": [
1,2
],
"title": "재능 기부"
}
----WebKitFormBoundary7MA4YWxkTrZu0gW
// CURL
curl --location --request POST 'http://localhost:8080/donations' \
--header 'Authorization: Bearer 로그인 후 발급된 토큰' \
--form 'file=@"/Users/buli/images/rabbit.png"' \
--form 'file=@"/Users/buli/images/mask.png"' \
--form 'request="{
\"category\":\"재능기부\",
\"content\": \"기부할래요\",
\"quality\": \"나쁨\",
\"tags\": [
1,2
],
\"title\": \"재능 기부\"
}";type=application/json'
응답 값(200)
{
"data": 1, // 해당 게시글의 식별자 아이디 반환
"message": "success"
}