0
votes

I am stuck today at ios image uri path

It is giving me path like this.and it is uploading to server as it is so i can't load these images in my view. Please help me anyone

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

But i want the path something like this

file:///Users/USERNAME/Library/Developer/CoreSimulator/Devices/########-####-####-####-############/data/Containers/Data/Application/########-####-####-####-############/Documents/########-####-####-####-############.png

Here is the link of a similar unanswered question - After Image Uploading, image uri is null for iOS alone in React Native

1

1 Answers

0
votes

One way is to use react-native-fs. It has a copyAssetsFileIOS method which generates absolute path from an asset. The following sample copies the photo to the temp directory and gets its path:

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)
    } 
}