收藏
回答

'savefile在ios下提示saveFile:fail it is not a temp'?

 const tempPath = `${wx.env.USER_DATA_PATH}/temp_${fileName}`;


  // 先写入临时文件

  fs.writeFile({

    filePath: tempPath,

    data: buffer,

    encoding: 'binary',

    success: () => {

      console.log('文件写入成功', tempPath);


      // 确保临时文件路径是有效的

      fs.getFileInfo({

        filePath: tempPath,

        success: (res) => {

          console.log("临时文件已成功创建:", res);

        },

        fail: (err) => {

          console.error("临时文件路径创建失败:", err);

        }

      });


      // // 再将临时文件保存到永久路径

      // fs.saveFile({

      //   tempFilePath: tempPath,  // 使用刚才写入的临时文件路径

      //   success: (res) => {

      //     const savedFilePath = res.savedFilePath;

      //     console.log('保存的文件路径:', savedFilePath);

为什么一直是saveFile:fail it is not a temp

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

3 个回答

  • 森胖胖
    森胖胖
    2024-12-18

    解决了吗解决了吗

    2024-12-18
    有用
    回复 2
    • 张灵玉
      张灵玉
      2024-12-20
      不自动把临时保存保存到本地了,利用微信的分享和下载功能手动保存就可以了
      2024-12-20
      回复
    • 森胖胖
      森胖胖
      2024-12-20回复张灵玉
      好的,谢谢
      2024-12-20
      回复
  • showms
    showms
    2024-11-19

    不是异步问题吗

    fs.saveFile应该得在writeFile回调里面执行吧

    2024-11-19
    有用
    回复 1
    • 张灵玉
      张灵玉
      2024-11-19
      没截图完,是在回调里完成的后面太多了,这个问题好像19年到现在一直有,应该是不能这样子的 ,安卓系统可以应该才是bug
      2024-11-19
      回复
  • ZHOU
    ZHOU
    发表于小程序端
    2024-11-19

    你这是偷偷保存微信缓存目录里的文件吗?感觉不会让你这样骚操作呀😂

    2024-11-19
    有用
    回复 1
    • 张灵玉
      张灵玉
      2024-11-19
      因为有些是要重启后还保存使用这个文件,先保存临时文件在保存下来防止重启或者突发状况找不到文件,但是这样子是不行的
      2024-11-19
      回复
登录 后发表内容