development/Mr.dJango 장고뽀개기

dJango Rest API 파일 다운로드 구현하기

foruheon 2019. 8. 6. 16:53

백엔드 단은 장고 restapi로 구현하였고 프론트단은 vue.js를 사용하였다

 

vue에서 파일 다운로드를 구현하기 위해선 아래와 같은 작업이 추가적으로 필요하다

 

let blob = new Blob([response.data], {type: response.headers['content-type']});
let link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click()
// this.$store.commit('SET_FILE_COUNT', response.data.data);
// this.$store.commit('SET_FILE_LIST', response.data.data);
// this.showFile = !this.showFile;

 

 

다음번에 좀더 디테일하게 적겠다.