wx.saveFileToDisk 可以在window微信客户端小程序使用,mac端微信小程序调?
发布于 5 年前 作者 liaolei 4106 次浏览 来自 官方Issues

微信pc端使用保存文件到磁盘,

window端下载保存文件时小文件正常,大文件(超过10M)卡顿,小程序假死,cpu飙升,但是下载能完成,下载后小程序能正常使用

mac端小程序保存文件直接报错,错误如图:

下载的是字体文件,域名已经添加白名单,代码如下:

//示例字体下载url="https://hellofonts.oss-cn-beijing.aliyuncs.com/汉仪尚巍手书/5.00/HYShangWeiShouShuW.ttf"
//字体如需商用,请到汉仪官网购买
let filePath = wx.env.USER_DATA_PATH + '/' + font.ProductName + font.ProductFileUrl.substr(font.ProductFileUrl.lastIndexOf("."))      
let downloadTask = wx.downloadFile({
                url: 文件url,
                filePath: filePath,
                success(res) {
                    if (res.statusCode === 200) {
                        wx.saveFileToDisk({
                            filePath: res.filePath,
                            success(re) {
                                console.log(re)
                                callback(re)
                            },
                            fail(e) {
                                console.log(e)
                            }
                        })
                    } else {
                        wx.showToast({
                            title'下载失败',
                            icon'none'
                        })
                    }
                },
                fail(res) {
                    
                    wx.showToast({
                        title'下载失败',
                        icon'none'
                    })
                }
            })
回到顶部