You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Android端无法覆盖文件路径中的图片问题求助

React Native Android端无法覆盖文件路径中的图片问题求助

各位好,我现在遇到一个棘手的问题——在Android设备的外部存储中保存文件时,始终无法覆盖已存在的文件。

我已经尝试了react-native-fs和rn-fetch-blob两个库,但得到的结果完全一样,都没法覆盖文件。

我检查过权限,读写权限都已经申请并开启了;甚至试过先删除目标文件再写入,但删除操作也没生效,感觉所有操作都没有按预期工作。

下面是我尝试写入文件的代码,麻烦大家帮忙看看哪里出问题了?

const takeSnapshot = () => {
  if (canvas.current) {
    const snapshot = canvas.current.makeImageSnapshot();
    const data = snapshot?.encodeToBase64(ImageFormat.JPEG, 100);
    
    if (data) {
      const fileName = 'skiaImgRef.jpg';
      var skiaPath = `file://${RNFS.DocumentDirectoryPath}/${fileName}`;

      // write the file
      RNFS.writeFile(skiaPath, data, 'base64')
        .then(success => {
          getMediaThumb(
            `file://${RNFS.DocumentDirectoryPath}/${fileName}`,
            0,
          );
          passOnImageSkia(
            `file://${RNFS.DocumentDirectoryPath}/${fileName}`,
          );
        })
        .catch(err => {
          console.log(err.message);
        });
    }
  }
};

备注:内容来源于stack exchange,提问作者hugger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 12:14:28