Vue axios request binary stream excel file, response garbled

:axiospostexcelresponse


response


forced text opening or garbled

May.28,2021

Last update:

since the landlord has adopted my answer, but I still want to talk about some questions carefully. For this reason, I have written the following code. For convenience, I directly download a xls that exists in the root directory of the server.

axios.get('http://127.0.0.1/1.XLS', {
                responseType: 'blob' //blob
            })
            .then(response => {
                console.log(response);//response
                let url = window.URL.createObjectURL(response.data);
                console.log(url)
                var a = document.createElement("a");
                document.body.appendChild(a);
                a.href = url;
                        a.download = '2.xls';
                        a.click();
                        window.URL.revokeObjectURL(url);
            })
            .catch(err => {
                console.log(``);
               
                console.log(err);
            })


responsedata blob Object

createObjectURL blob File

URL


response.data blob Object let url = window.URL.createObjectURL(new Blob([res.data]))

:
1. responseType: 'blob' responseType
2.axios

:

ExcelExcel

:
responseType: 'arraybuffer' responseType: 'blob'

let objectUrl = URL.createObjectURL(res.data);


responsetextexcelresponse



responseType: 'blob' blob {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"} excel


postman...




mockjsrequire('mockjs')
mock
image
mockjs1
image


1.office
2.QQpostmanoffice
3.wps


image

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ffcf-2bc55.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ffcf-2bc55.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?