- 침입수 분석 화면 변수명 오타 수정 - 분석결과 화면 수정 및 조회 기능 구현, 파일 다운로드, 삭제 구현중 - 중점우수토실 상세정보 화면 구현 - verticalTable.tsx에 테이블 추가 - contentLayout.tsx에 className prop 추가 - fileDownload.ts에 BASE_URL 추가
28 lines
836 B
TypeScript
28 lines
836 B
TypeScript
const BASE_URL = process.env.NEXT_PUBLIC_SERVER_API_URL || '';
|
|
|
|
export const handleDownload = async (api:string, fileNm:string) => {
|
|
try {
|
|
const response = await fetch(api, {
|
|
method: 'GET',
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error('파일 다운로드 실패');
|
|
}
|
|
|
|
const blob = await response.blob();
|
|
const url = window.URL.createObjectURL(blob);
|
|
|
|
// 다운로드를 트리거할 가짜 <a> 태그 생성
|
|
const link = document.createElement('a');
|
|
link.href = url;
|
|
link.download = fileNm; // 원하는 파일명 지정
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
|
|
// 메모리 해제
|
|
link.remove();
|
|
window.URL.revokeObjectURL(url);
|
|
} catch (error) {
|
|
console.error('다운로드 중 오류 발생:', error);
|
|
}
|
|
}; |