파일 다운로드 코드 - 실제로 사용했던 코드로 API 로 파라미터를 넘기면, 결과를 엑셀파일로 내려받는 코드

function requestResult() {
            var year = document.getElementById("year").value;
            var month = document.getElementById("month").value;
            var filename = "";
            alert("year : " + year + " month : " + month);

            if (month >= 1 && month <= 9) {
                month = '0' + month;
            }

            fetch("/files/download/result/" + year + "/" + month, {
                method: "get",
                headers: {
                    'Content-Type': 'application/octet-stream',
                }
            }).then((res) => {
                const disposition = res.headers.get('Content-Disposition');
                filename = disposition.split(/;(.+)/)[1].split(/=(.+)/)[1];
                if (filename.toLowerCase().startsWith("utf-8''"))
                    filename = decodeURIComponent(filename.replace(/utf-8''/i, ''));
                else
                    filename = filename.replace(/['"]/g, '');
                return res.blob();
            }).then(blob => {
                var url = window.URL.createObjectURL(blob);
                var a = document.createElement('a');
                a.href = url;
                a.download = decodeURI(filename).replace(/\+/g, " ")
                document.body.appendChild(a);
                a.click();
                a.remove();
            })
        };