文件流请求 - 优化版
此文件流的使用方法只能用来测试
为什么这种方法只能测试用呢?后端返给你的文件流是一个一个的地址,取一个的话还好,一次性取多个的话就会有比较麻烦,所以我们也可以通过id去取,(这个方法稍后更新)
// import { wechatV1 as v1 } from 'services/config';
// import { getAccessToken } from 'utils/token';
// 文件流的多此一举请求
componentDidMount() {
const that = this;
fetch('http://172.16.20.202/api/v1/wechat/content/13/media', {
method: 'GET',
responseType: 'blob',
})
.then(res => {
console.log(res,89);
return res.blob()
}).then(res => {
const reader = new FileReader();
reader.readAsDataURL(res);
reader.onload = (e) => {
that.setState({ img: e.target.result })
console.log(e.target.result,0);
}
})
}
// 测试用
// componentDidMount() {
// // const token = getAccessToken();
// // fetch(`${v1}/wechat/content/3/media`, {
// // headers: { authorization: `Bearer ${token}` },
// // responseType: 'blob',
// // })
// // const token = getAccessToken();
// // fetch(`https://wechat-api.car-tmed.com/api/v1/wechat/content/292/media`, {
// // headers: { authorization: `Bearer ${token}` },
// // responseType: 'blob',
// // })
// // .then(res => {
// // // console.log(res,909);
// // return res.blob()
// // }).then(res => {
// // const reader = new FileReader();
// // reader.readAsDataURL(res);
// // reader.onload = (e) => {
// // console.log(e.target.result)
// // // console.log(e.target.result, 930);
// // // console.log(res,34);
// // }
// // })
// }