Front/JS & jQuery

[js] 파일전송 클라이언트 전송 예제

오선지♬ 2024. 12. 18. 20:17
728x90
반응형
const data = { key1: "value1", key2: "value2" };
const formData = new FormData();
formData.append("req", JSON.stringify(data));
formData.append("files", fileInput.files[0]); // 첫 번째 파일
formData.append("files", fileInput.files[1]); // 두 번째 파일

fetch("/ecrdSave", {
    method: "POST",
    body: formData
}).then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error("Error:", error));
728x90
반응형