收藏
回答

小程序2.0基础版本2.25.2将图片保存到本地部分安卓出现报错怎么解决?

    const path = `${wx.env.USER_DATA_PATH}/fistTest.png`
    // 获取小程序的文件系统
    const fsm = wx.getFileSystemManager()
    // 把arraybuffer数据写入到临时目录中
    console.log(path,fsm, 'path')
    try {
      fsm.accessSync('wxfile://ad/interstitialAdExtInfo.txt');
      console.log('文件存在');
    } catch (e) {
      console.error('文件不存在', e);
    }


    fsm.writeFile({
      filePath: path,
      data: base64?.replace(/^data:image\/\w+;base64,/''),
      encoding'base64',
      success() => {
        wx.getSetting({
          successres => {
            console.log(res,8999)
            let authSetting = res.authSetting
            if (!authSetting['scope.writePhotosAlbum']) {
              wx.authorize({
                scope'scope.writePhotosAlbum',
                success() {
                  console.log('授权了相册')
                  wx.downloadFile({
                    url: path, //仅为示例,并非真实的资源
                    success(res) {
                      console.log('保存图片')
                      // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
                      if (res.statusCode === 200) {
                        wx.saveImageToPhotosAlbum({
                          filePath: res.tempFilePath,
                          success() => {
                            wx.showToast({
                              title'保存海报成功',
                              icon'success',
                              duration2000
                            })
                          }
                        });
                      }
                    }
                  })
                }
              })
            } else {
              console.log('已经授权过相册')
              wx.saveImageToPhotosAlbum({
                filePath: path,
                success() => {
                  wx.showToast({
                    title'保存海报成功',
                    icon'success',
                    duration2000
                  })
                }
              });
            }
          }
        })
      }
    })

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

1 个回答

  • Demons
    Demons
    2024-12-23

    报错是隐私没更新

    2024-12-23
    有用
    回复
登录 后发表内容