react-native-cameraroll / react-native-cameraroll

CameraRoll is a react-native native module that provides access to the local camera roll or photo library.
MIT License
905 stars 434 forks source link

Uri and file path doesn't work with jpeg for reading file base 64 IOS [Error: No such file] #593

Open KOKOdeveloper opened 4 months ago

KOKOdeveloper commented 4 months ago

Hello I'm using this library to get photos from gallery and it works perfect with HEIC format. I use like this

` const getGalleryImages = async (): Promise<IImageItem[]> => {
    return CameraRoll.getPhotos({
      first: 4,
      assetType: 'Photos',
      groupTypes: 'All',
      include: ['fileSize', 'filename', 'fileExtension', 'imageSize'],
    })
      .then(async res => {
        let images = [];
        for (let i = 0; i < res.edges.length; i += 1) {
          const {image} = res.edges[i].node;
          const imageData = await CameraRoll.iosGetImageDataById(image.uri, {
            convertHeicImages: true,
            quality: 1,
          });
          const data64 = await ReactNativeBlobUtil.fs.readFile(
            imageData.node.image.filepath ?? '',
            'base64',
          );
          images.push({
            image: imageData.node.image.filepath ?? '',
            name: imageData.node.image.filename ?? '',
            base64: data64,
            selected: false,
          });
        }
        return images;
      })
      .catch(e => {
        return [];
      });
  };`

But this code doesn't work if the file is "JPEG". So when I use this const data64 = await ReactNativeBlobUtil.fs.readFile( imageData.node.image.filepath ?? '', 'base64', );

It return [Error: No such file 'file:///Users/*****/Library/Developer/CoreSimulator/Devices/26DA6F20-97EA-439A-9727-15D3926440A2/data/Media/DCIM/100APPLE/IMG_0006.JPG

or with the image.uri:

const data64 = await ReactNativeBlobUtil.fs.readFile( image.uri, 'base64', );

It return "error such file 'ph://CC95F08C-88C3-4012-9D6D-64A413D254B3/L0/001"

I realise that when I use "CameraRoll.iosGetImageDataById" with option for convert HEIC format It create temp "filePath" that is returned and it works fine for reading base 64, path example (/Users/***/Library/Developer/CoreSimulator/Devices/26DA6F20-97EA-439A-9727-15D3926440A2/data/Containers/Data/Application/8B7CF391-64E8-4489-BB8F-49D5DE1B2C5A/tmp/IMG_0111.JPEG).

Can someone help me how to get correct file path for JPG how I can use ReactNativeBlobUtil.fs.readFile to get base 64.?

Keanu2431 commented 4 months ago

Did you find a solution yet? @KOKOdeveloper

KOKOdeveloper commented 3 months ago

Not yet, I'm waiting some of the contributors to present solution. Currently I just add "mimeTypes: ['image/heic']," to filter just "HEIC" format to complete the flow, but that's not okey from UX perspective want to show JPG as well ..

Arjan-Zuidema commented 1 month ago

Try https://github.com/itinance/react-native-fs maybe that package can read those files. This is not an issue with this package should fix as it returns the correct uri