programing

Vue.js로 대용량 파일을 스트리밍 다운로드가 가능한가?

prostudy 2022. 4. 16. 09:46
반응형

Vue.js로 대용량 파일을 스트리밍 다운로드가 가능한가?

미리 많은 사람에게 감사하다

그래서 다운로드를 스트리밍할 수 있는 해결책(구글을 검색했지만 아무것도 찾지 못했다)을 찾고 있다.내 말은, 나는 csv 파일로 데이터를 내보내고 있지만, 때때로 데이터는 내 백엔드와 사용자 모두에게 무거운 7MB까지 될 수 있다.

나는 Vue로 쓰고 있다 우리의 백엔드는 PHP로 쓰여져 있다 (Yi 1.1)

현재 파일을 다운로드하는 방법

 exportCsv() {
                this.loading = true;
                let payload = this.csvPayload; /// computed property
                this.$http
                    .post("/statistics/apiurl", payload)
                    .then(response => {
                        this.loading = false;
                        const url = window.URL.createObjectURL(new Blob([response.data]));
                        const link = document.createElement('a');
                        link.href = url;
                        link.setAttribute('download', 'excelFile.csv'); //or any other extension
                        document.body.appendChild(link);
                        link.click();
                    })
                    .catch(error => {
                        this.loading = false;
                        this.campaignsLoading = false;
                        console.log("Problem fetching csv file: ", error.message);
                    });
            },

대단해! 하지만 역시 파일이 정말 크면 백엔드와 사용자에게는 무거워.

말했듯이 파일을 스트리밍 다운로딩할 수 있는 방법은 없을까?아니면 다른 파일로 관측 가능한 데이터를 생성해서 데이터를 듣고 콜백을 내 vue 컴포넌트로 다시 보낼 수 있을 것 같아서...

참조URL: https://stackoverflow.com/questions/58579249/is-it-possible-to-stream-download-large-files-with-vue-js

반응형