프론트에서 파일을 변수로 받는 부분에 .value
를 붙여서 file 이 아니라 str 형태로 전달이 된 것이다. .value
부분부터 지워주면 된다.
async function DrugCreate() {
const input = document.getElementById("upload_file") // 여기 .value 를 없애줬다
if (input) {
img = input.files[0]
console.log(img.name)
const formData = new FormData();
formData.append('img', img);
const response = await fetch('http://127.0.0.1:8000/drugs/create/', {
// headers: {
// 'content-type': 'application/json',
// },
method: 'POST',
body: formData
})
}
alert(response['message'])
location.reload()
}