【问题标题】:How can I get picked image from ios camera roll exact URI path?如何从 ios 相机胶卷确切的 URI 路径中获取选取的图像?
【发布时间】:2020-07-30 05:40:59
【问题描述】:

我今天卡在 ios image uri path

它给了我这样的路径。它正在上传到服务器,所以我无法在我的视图中加载这些图像。请任何人帮助我

assets-library://asset/asset.PNG?id=CE542E92-B1FF-42DC-BD89-D61BB70EB4BF&ext=PNG

但我想要这样的路径

file:///Users/USERNAME/Library/Developer/CoreSimulator/Devices/#######-####-####-####-###### ######/数据/容器/数据/应用程序/########-####-####-####-########### #/文档/########-####-####-####-############.png

这是一个类似的未回答问题的链接 - After Image Uploading, image uri is null for iOS alone in React Native

【问题讨论】:

    标签: ios react-native image-processing uri


    【解决方案1】:

    一种方法是使用react-native-fs。它有一个copyAssetsFileIOS 方法,可以从资产生成绝对路径。以下示例将照片复制到临时目录并获取其路径:

    import RNFS from 'react-native-fs';
    
    getAbsolutePath = async (assetPath) => {
        const destination = `${RNFS.TemporaryDirectoryPath}${Math.random().toString(36).substring(7)}.png`;
        try {
          let absolutePath = await RNFS.copyAssetsFileIOS(assetPath, destination, 0, 0);
          console.log(absolutePath)
        } catch(error) {
          console.log(error)
        } 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多