收藏
回答

如何从云存储下载最新文件?

已经通过云函数将云存储中的文件更新,PC端云开发平台上都能下载到最新文件,

可是小程序从云存储中下载的文件还是旧版本的文件。

小程序已经将下载的临时文件清除了。

以下是问题代码:

downloadCloudFile: function (resultFileUrl) {

   wx.clearStorage()

   wx.getSavedFileList({

     success: function (res) {

       console.log("savedFileListLength:" + res.fileList.length)

       for (var i = 0; i < res.fileList.length; i++) {

         wx.removeSavedFile({

           filePath: res.fileList[i].filePath,

         })

       }

     }

   })

   wx.cloud.downloadFile({

     fileID: resultFileUrl,

     success: function(res) {

       wx.hideLoading()

       wx.showToast({

         title: '成功',

       })

       console.log('tempFilePath:' + res.tempFilePath)

       // 保存文件

       wx.saveFile({

         tempFilePath: res.tempFilePath,

         success: function(res) {

           console.log('savedFilePath:' + res.savedFilePath)

           var savedFilePath = res.savedFilePath;

           // 打开文件

           wx.openDocument({

             filePath: savedFilePath,

             success: function(res) {

               console.log('打开文档成功')

             },

           });

         },

         fail: function(err) {

           console.log('保存失败:', err)

         }

       })

     },

     fail: function(err) {

       wx.hideLoading()

       console.log('下载失败:', err);

     },

   })

 },



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

1 个回答

  • 拾忆
    拾忆
    2019-10-24

    可能有缓存,文件名后加?时间戳试试

    2019-10-24
    有用 1
    回复 1
    • 刘宏清 ʘᴗʘ
      刘宏清 ʘᴗʘ
      2019-10-24
      是有缓存,加上时间戳,问题解决,谢谢!
      2019-10-24
      回复
登录 后发表内容
问题标签