В этой статье я покажу вам, как загрузить большой двоичный объект в файл csv / xl.
Я собираюсь использовать HTTP-клиент в Angular.
Вот код !!
let headers = new Map<string, string>(); headers.set('Accept', // this line is imp if blob is csv or xl 'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet' ); // here you can append your custom headers with the help of header object let queryString= ""; // here you can insert your queries const options = new RequestOptions({headers: this.headers, responseType: ResponseContentType.ArrayBuffer}//this is the imp line ); let response = this.http.get(url + '?' + queryString, options); // now subscribe this object response.subscribe((response) => { // @ts-ignore let myBlob = new Blob([response._body], {type: 'application/vnd.oasis.opendocument.spreadsheet'}); let downloadUrl = URL.createObjectURL(myBlob); let a = document.createElement('a'); a.href = downloadUrl; a.download = 'report.xlsx';// you can take a custom name as well as provide by server // start download a.click(); // after certain amount of time remove this object!!! setTimeout( ()=> { URL.revokeObjectURL(downloadUrl); }, 100); });
С помощью этого кода вы можете загрузить большой двоичный объект, но самое главное, что перед передачей объекта ответа вы должны проверить тип объекта ответа и передать только большой двоичный объект ответа.