wx.downloadFile 手机上提示 网络连接已中断
发布于 5 年前 作者 xiulan98 13495 次浏览 来自 问答

wx.downloadFile 下载视频 报错,进入 fail 回调,回掉参数:{“errMsg”:“downloadFile:fail 网络连接已中断。”}

而在fail 回掉里面我立即调用了 wx.getNetworkType  返回网络状态非 none。该bug非必现,但是在线上已经有很多用户反馈了,而且都是ios真机下发现的,麻烦官方看看这块是否有漏洞。

6 回复

下面是实际视频列表地址:

["https://o4wbikkhf.qnssl.com/bf786a6f-04c0-5e44-a623-719c50c1319d","https://o4wbikkhf.qnssl.com/c73d9cca-cae8-5386-b360-945fb97519a9","https://o4wbikkhf.qnssl.com/30ea4a60-3fe8-5585-a716-bb09e3c49151","https://o4wbikkhf.qnssl.com/e0b6292a-33eb-51c2-9592-c8976d8ece30","https://o4wbikkhf.qnssl.com/eddd3363-90b8-5fff-a4f9-ba1bf7afaae7","https://o4wbikkhf.qnssl.com/f60cace9-a735-5850-a21b-52c9ebc45dfe","https://o4wbikkhf.qnssl.com/1a514988-39c7-5c28-98f4-582055a1fb58","https://o4wbikkhf.qnssl.com/195aa019-b1bd-5835-bb48-2f07fbd83149","https://o4wbikkhf.qnssl.com/0a7baf1f-0044-52e4-b432-3ad92cbf0db8","https://o4wbikkhf.qnssl.com/ee8f967f-d90f-59a6-b25e-91428ca62139","https://o4wbikkhf.qnssl.com/9812d3df-7d14-506e-bae0-f5c443715a72","https://o4wbikkhf.qnssl.com/ad637a51-0170-55d2-9db0-f48612d1fab6","https://o4wbikkhf.qnssl.com/0c1c873f-5ba1-5140-9dbd-52981219fe62","https://o4wbikkhf.qnssl.com/397907a2-8d94-5a5f-b093-3b4a5c2ea455","https://o4wbikkhf.qnssl.com/8ca15cb6-ccc9-5a05-8ee0-e76718b1e10b","https://o4wbikkhf.qnssl.com/10c9d704-8bb1-51b0-8551-bb17a7e14c39","https://o4wbikkhf.qnssl.com/a574b6d9-3abb-5a53-ae85-16e4c3c29c5e","https://o4wbikkhf.qnssl.com/c01c39a8-d587-5192-9753-43d639ffdec5","https://o4wbikkhf.qnssl.com/bfd7a277-5299-5ddc-8fdf-c74745b1221b","https://o4wbikkhf.qnssl.com/48f3fb21-77c9-5bc3-8fed-1f6479f27ad7","https://o4wbikkhf.qnssl.com/38c6dcd4-8eec-5de4-bf5d-329cde96c96d","https://o4wbikkhf.qnssl.com/7772433e-7e24-5a89-94c0-1cafd77334e9","https://o4wbikkhf.qnssl.com/f6b74509-273d-51db-a314-e15ddc2c8b80","https://o4wbikkhf.qnssl.com/58bb726f-1156-563d-90c9-359534bd28d6","https://o4wbikkhf.qnssl.com/8b063c7e-1da1-53ff-88d2-1b994c346bb9","https://o4wbikkhf.qnssl.com/c68296f5-ddb2-5a3f-b68b-b8bd0a3938c9","https://o4wbikkhf.qnssl.com/cd5f603b-fbdf-5335-866c-48208e910069","https://o4wbikkhf.qnssl.com/73c81744-76d0-5d4b-b818-611c29b0aec3","https://o4wbikkhf.qnssl.com/61a974b7-f5ef-591b-817b-62ed68b60077","https://o4wbikkhf.qnssl.com/582e3d8b-4319-556b-8d01-16f9e1faf8f3","https://o4wbikkhf.qnssl.com/65bf5439-b63e-54e4-b34d-2565fd41c183","https://o4wbikkhf.qnssl.com/b8d383a8-5541-5a85-a6e5-48d8bd1c799a","https://o4wbikkhf.qnssl.com/e636d2e4-f18a-50f4-ba15-50c77429df5f","https://o4wbikkhf.qnssl.com/0236567d-4474-525b-a627-6b5e7a7bb648","https://o4wbikkhf.qnssl.com/ebc3c974-12a7-52c2-9b20-42884a23ee5b","https://o4wbikkhf.qnssl.com/bcfa67d8-bcf5-5010-a869-ea3608f714b4","https://o4wbikkhf.qnssl.com/0c4dea1a-09d6-5ee4-b661-65d4d22bf1ab"]

+1   出现了同样的问题

请问这个问题downloadFile 下载失败,  微信接口返回错误信息为:{“errMsg”:“downloadFile:fail 网络连接已中断。”}这块是官方的漏洞吗

你好,请提供一下出现问题的机型和微信版本,以及能复现问题的简单代码示例。

var app={getFileInfo(filePath){

    var ctx = this;

    return new Promise((resolve, reject) => {

      wx.getFileInfo({

        filePath,

        complete( res ){

          res.errMsg == ‘getFileInfo:ok’ ? resolve(res) : reject(res);

        }

      })

    })

  },

  getNetworkType(){

    return new Promise((resolve, reject) => {

      wx.getNetworkType({

        complete(res) {

          resolve(res);

        }

      })

    })

  },

  downloadFile( url ){

    return new Promise((resolve, reject) => {

      wx.downloadFile({

        url,

        success(res) {

          resolve(res);

        },

        fail(res) {

          reject(res);

        }

      })

    })

  }

}

//下面是下载模块

//var app = getApp();上面的方法就放在app上,这里简单模拟就直接定义了app如上代码。

var Promise = require(’…/…/…/…/utils/lib/es6-promise.min.js’);

var uploadVideoCache  = app.globalData.uploadVideoCache;

var cacheTime = 3*60*1000;//缓存时间

 var util = {

getLocalUrl(url) {

    var cache = uploadVideoCache;

    var key = encodeURIComponent(url);

    var context = this;

    return new Promise((resolve, reject) => {

      /*return setTimeout(()=>{

        resolve({ code: 200, url: url });

      });*/

      if (cache[key] && Date.now() - cache[key].time <= cacheTime) {

        console.log(‘有文件缓存’ + cache[key].url);

        resolve({ code: 200, url: cache[key].url });

      } else {

        console.log(‘开始下载:’+url);

        context.downFile(url, key, cache, resolve);

      }

    });

  },

  downFile(url, key, cache, resolve) {

    app.downloadFile(url).then(res => {

      console.log([‘下载成功’, ‘原:’+url, ‘下载后:’+res.tempFilePath]);

      cache[key] = { url: res.tempFilePath,time:Date.now()};

      resolve({ code: 200, url: res.tempFilePath });

    }, err => {

      console.log([‘downloadFile_Error’,url,err]);

      app.getNetworkType().then(res=>{

        console.log([‘下载失败,网络:’, url, res.networkType]);

        resolve({ code: res.networkType==‘none’?500:201, url: url });

        res.networkType != ‘none’ && app.errorLog({//这里是给服务器发送错误日志的,目前服务端收到了很多这个错误

          url: ‘downloadFile_Error’,

          code: 30201,

          userId: app.globalData.userId || ‘’,

          serverData: JSON.stringify(err).substr(0, 500)

        });

      });

    }).catch(err=>{

      app.getNetworkType().then(res => {

        console.log([‘下载失败catch,网络:’ + res.networkType, url, err]);

        resolve({ code: res.networkType == ‘none’ ? 500 : 202, url: url });

        res.networkType != ‘none’ && app.errorLog({

          url: ‘downloadFile_Error’,

          code: 30202,

          userId: app.globalData.userId || ‘’,

          serverData: JSON.stringify(err).substr(0, 500)

        });

      });

    });

  }

}// end util

现在的情况是进去页面下载第一个视频,开始播放,然后下载后一个视频,调用方法 util.getLocalUrl();

视频播放完成自动切换到下一个视频,然后又自动下载下下一个视频。

发现的问题是:downloadFile 下载失败,  微信接口返回错误信息为:{“errMsg”:“downloadFile:fail 网络连接已中断。”}

回到顶部