收藏
回答

ios15.6下载文件失败?

ios15.6下载文件失败,我13.6正常下载预览,安卓也正常下载预览,失败的为15.6,成功的为13.6

回答关注问题邀请回答
收藏

2 个回答

  • Demons
    Demons
    2022-11-15

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2022-11-15
    有用
    回复 2
  • Ming
    Ming
    2022-11-15
    // 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() {
    
    
      }
    })
    
    2022-11-15
    有用
    回复
登录 后发表内容