为什么 fetch await 不等待文件下载

问题描述

我正在尝试使用 fetch 从 googleapi 服务器下载 apk(我无法使用任何插件,并且由于 cors 问题,唯一的解决方案是使用 fetch 代替 ionic native http)

显然 await 不起作用,因为它试图在数据流仍在进行时保存文件文件为 11Mb)。

async saveApk(){
  this.blob = await this.download(this.url);
  let apk = new Blob([this.blob],{type:'application/vnd.android.package-archive'});
  this.file.writeFile(this.file.cacheDirectory,'test.apk',apk,{ replace: true});
}

async download(url){
  try {
    const request = new Request(url.slice(0,-5),{
      method: 'GET',mode: 'no-cors',credentials: 'include'
    });
    let response = await fetch(request);
    let data = await response.blob();
    return data;
  } catch (err) {
    console.error(err)
  }
}

我已经尝试解决它三天了,但我找不到缺陷。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)