JavaScript

[JavaScript] axios를 이용한 파일 업로드

purecho 2023. 8. 22. 19:29
/* 파일 전송 */
function fileFormSubmit() {
    // 파일 데이터
    const formData = new FormData();
    formData.append("file", file.files[0]);

    // 폼 전송
    axios({
        method: 'post',
        url: '/admin/excel',
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        data: formData,
        timeout : 3000,
    }).then(function (response) {
        alert("데이터 전송 완료");
    }).catch(function (error) {
        alert(error);
    }).finally(function () {

    });
}