如何获取文件流 - 优化版

文件流请求 - 优化版

此文件流的使用方法只能用来测试

为什么这种方法只能测试用呢?后端返给你的文件流是一个一个的地址,取一个的话还好,一次性取多个的话就会有比较麻烦,所以我们也可以通过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);
  //   //     }
  //   //   })
  // }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值