如何从云存储下载最新文件?
发布于 6 年前 作者 yang19 12230 次浏览 来自 官方Issues

已经通过云函数将云存储中的文件更新,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 回复

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

回到顶部