前端接收bolb流文件下载成为csv格式文件
时间: 2023-08-16 16:41:06 浏览: 60
要在前端接收Blob流文件并下载为CSV格式文件,可以使用以下步骤:
1. 发送请求获取CSV文件的Blob流数据:
```javascript
axios.get('url/to/your/csv', { responseType: 'blob' })
.then(response => {
const blob = new Blob([response.data], { type: 'text/csv' });
// 处理blob数据
})
.catch(error => {
console.log(error);
});
```
2. 将Blob数据转换为CSV格式并下载:
```javascript
axios.get('url/to/your/csv', { responseType: 'blob' })
.then(response => {
const blob = new Blob([response.data], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'data.csv';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
})
.catch(error => {
console.log(error);
});
```
这样,就可以在前端接收并下载Blob流文件为CSV格式文件了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)