微信小程序saveFile:fail the maximum size of the file storage limit is exceeded

话不多说,上解决方案

wx.getSavedFileList({  // 获取文件列表
        success(res) {
          res.fileList.forEach((val, key) => { // 遍历文件列表里的数据
            // 删除存储的垃圾数据
            wx.removeSavedFile({
              filePath: val.filePath
            });
          })
          setTimeout(function(){
            wx.saveFile({
              tempFilePath: ptah,
              success: function success(resp) {
                wx.hideLoading()
                wx.showToast({
                  title: '长按图片保存到手机',
                  icon: 'none',
                  duration: 2000
                })
                let preUrl = resp.savedFilePath
                wx.previewImage({
                  current: preUrl, // 当前显示图片的http链接
                  urls: [preUrl] // 需要预览的图片http链接列表
                })
              },
              fail: function (resp) {
              }
            });
          },1500)
          
        }
      })

问题描述:
最近小程序上做了一个生成海报的功能,开始功能一直没问题,上线以后也能生成,但是用了几次以后就没法生成了,逐行排除代码,原来是小程序的本地存储满了。

报错信息:

saveFile:fail the maximum size of the file storage limit is exceeded

报错原因:

微信文档中描述的是 本地文件存储的大小限制为 10M

解决方案
wx.getSavedFileList,获取小程序本地存储的文件列表,再通过wx.removeSavedFile将垃圾文件删除即可。我的代码加了setTimeout保证执行顺序。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值