小程序
小游戏
企业微信
微信支付
扫描小程序码分享
ios15.6下载文件失败,我13.6正常下载预览,安卓也正常下载预览,失败的为15.6,成功的为13.6
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
// pages/downLoad/downLoad.ts Page({ /** * 页面的初始数据 */ data: { url: '', openDocumentTypeList: ['doc','docx','xls','xlsx','ppt','pptx','pdf'], previewImageTypeList: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let that = this // let url = decodeURIComponent(options.url) // let fileType = options.fileType let fileType = 'png' this.setData({ url: 'https://img.successchannel.net/data/clickpaas/files/cpfile/t_K3002205/QINIU_20221111101115fXAsls.png?attname=%E6%88%AA%E5%B1%8F2021-12-14+%E4%B8%8B%E5%8D%883.52.43.png&fileId=059e7d30-cbfd-4436-9c27-5fee13d10aca&ext=png' }) // wx.showLoading({ // title: '加载中...', // }) wx.downloadFile({ // 下载文件 url: that.data.url, success: function (res) { that.setData({ tempFilePath:res.tempFilePath }) let filePath = res.tempFilePath // 文件临时路径 if(that.data.openDocumentTypeList.includes(fileType)) { wx.openDocument({ // 预览文件 filePath: filePath, fileType: fileType, showMenu: true, success: function (res) { // wx.hideLoading(); }, fail: function (error) { console.log(error); } }) } else if (that.data.previewImageTypeList.includes(fileType)) { wx.previewImage({ current: '', urls: [filePath], success: function () { // wx.hideLoading(); }, }) } else { wx.showToast({ title: '不支持的文件类型', icon: 'error' }) } }, fail: function (error) { console.log(error); wx.showToast({ title: '文件下载失败', icon: 'error' }) // wx.hideLoading() } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
// pages/downLoad/downLoad.ts Page({ /** * 页面的初始数据 */ data: { url: '', openDocumentTypeList: ['doc','docx','xls','xlsx','ppt','pptx','pdf'], previewImageTypeList: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let that = this // let url = decodeURIComponent(options.url) // let fileType = options.fileType let fileType = 'png' this.setData({ url: 'https://img.successchannel.net/data/clickpaas/files/cpfile/t_K3002205/QINIU_20221111101115fXAsls.png?attname=%E6%88%AA%E5%B1%8F2021-12-14+%E4%B8%8B%E5%8D%883.52.43.png&fileId=059e7d30-cbfd-4436-9c27-5fee13d10aca&ext=png' }) // wx.showLoading({ // title: '加载中...', // }) wx.downloadFile({ // 下载文件 url: that.data.url, success: function (res) { that.setData({ tempFilePath:res.tempFilePath }) let filePath = res.tempFilePath // 文件临时路径 if(that.data.openDocumentTypeList.includes(fileType)) { wx.openDocument({ // 预览文件 filePath: filePath, fileType: fileType, showMenu: true, success: function (res) { // wx.hideLoading(); }, fail: function (error) { console.log(error); } }) } else if (that.data.previewImageTypeList.includes(fileType)) { wx.previewImage({ current: '', urls: [filePath], success: function () { // wx.hideLoading(); }, }) } else { wx.showToast({ title: '不支持的文件类型', icon: 'error' }) } }, fail: function (error) { console.log(error); wx.showToast({ title: '文件下载失败', icon: 'error' }) // wx.hideLoading() } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })