wx.downloadFile 下载文件后缀名 为 unknown
发布于 5 年前 作者 weiren 17539 次浏览 来自 问答

    return new Promise(function(resolve, reject) {

        wx.downloadFile({

            url: conf.url + `${url}${data ? “?” + JSON.stringify(data) : “”}`,

            header: {

                ‘Cookie’: ‘JSESSIONID=’ + getApp().globalData.jsessionid

            },

            success: function(res) {

                if (res.statusCode === 200) {

                    console.log(res);

                    wx.saveFile({

                    tempFilePath: res.tempFilePath,

                    success(res){

                        console.log(res);

                        wx.openDocument({

                            filePath: res.savedFilePath,

                            success: function (res) {

                                console.log(‘打开文档成功’)

                            },

                            fail(res){

                                console.log(res);

                            }

                       })

                    },

                    fail(res){

                        console.log(“下载失败”)

                    }

                })

               resolve(res)

            } else {

                reject(res)

            }

            },

            fail: function(res) {

                reject(res);

            },

            complete: function(res) {

                if (complete) complete(res)

            },

        })

    })

3 回复

wx.downloadFile 传输格式,还有可以看下下载的格式是否微信支持。可以从这两个方面查下原因,暂未使用过微信下载api

回到顶部