maxim-kolesnikov / react-native-heic-converter

Convert your HEIC files with React Native
MIT License
68 stars 23 forks source link

Please i get this error !!! [TypeError: null is not an object (evaluating 'RNHeicConverter.convert')] #44

Open tdammy92 opened 1 year ago

tdammy92 commented 1 year ago

Am trying to convert an HEIC file from two places.

From @react-native-cameraRoll and from react-native-image-crop-picker

Used RNHeicConverter.convert() am not getting any result neither am i getting a response.

` const sendFile = async () => {

try {
  const res = await ImagePicker.openPicker({
    cropping: false,
    mediaType: 'photo',
    forceJpg: true,
  });

  RNHeicConverter.convert({path: res?.sourceURL}) 
    .then((res: any) => console.log(res))
    .catch((err: any) => console.log(err));

  if (res) {
    const file = {
      uri:
        Platform.OS === 'android'
          ? res?.path
          : res?.sourceURL,
      type: res?.mime,
      name:
        Platform.OS === 'android' ? Date.now().toString() : res?.filename,
    };

    // await postImage(file);
  }
} catch (error) {
  // console.log('file picker catch error', error);

}

}; `

Please i need help 🙏🏽

noumantahir commented 1 year ago

@tdammy92 I think it's more syntax error instead of package issue... you are trying to read res while res do no exist in the scope you are reading in....

either try... const res = await RNHeicConverter.conver() inside an async function or process res inside the promise response scope

 RNHeicConverter.convert({path: res?.sourceURL}) 
    .then((res: any) => {
         console.log(res)}
           if (res) {
             const file = {
               uri:
                 Platform.OS === 'android'
                   ? res?.path
                   : res?.sourceURL,
               type: res?.mime,
               name:
                 Platform.OS === 'android' ? Date.now().toString() : res?.filename,
             };
     )
    .catch((err: any) => console.log(err));
tdammy92 commented 1 year ago

@noumantahir, Pls ignore the if block.

Using this.

 RNHeicConverter.convert({path: res?.sourceURL}) 
    .then((res: any) => console.log(res))
    .catch((err: any) => console.log(err));

or

const selectedImage = async(item)=>{
    try{
          const convertedImage = await RNHeicConverter.convert({path: item?.sourceURL}) ;
            console.log(convertedImage)
            } catch(error) {
          console.log(error)
       }
 } 

I get the same error.

maxim-kolesnikov commented 1 year ago
Platform.OS === 'android'

Are u use Android? Which OS are we talking about?

tdammy92 commented 1 year ago

@maxim-kolesnikov @noumantahir

am using a camera roll, when a user clicks on any of the image i get the below object

{
  timestamp: 1522437259.365,
  type: "image",
  group_name: "All Photos",
  location: {
    altitude: 4.583391486392184,
    longitude: -122.50956666666667,
    latitude: 37.76007833333333,
    heading: 0,
    speed: 0.5513811087502415
  },
  image: {
    uri: "ph://CC95F08C-88C3-4012-9D6D-64A413D254B3/L0/001",
    extension: "heic",
    filename: "IMG_0111.HEIC",
    width: 4032,
    fileSize: 2808983,
    playableDuration: null,
    height: 3024
  }
}
const sendPhoto = async (item: any) => {
    if (item) {
     if (Platform.OS === 'ios') {
        RNHeicConverter.convert({path: item?.image?.uri})
          .then((res: any) => console.log('res from converter', res))
          .catch((err: any) => console.log('error from converter', err));
      }
  }
tdammy92 commented 1 year ago
Platform.OS === 'android'

Are u use Android? Which OS are we talking about?

Building for both OS. but currently testing for IOS.

ChristopherGabba commented 9 months ago

Getting the same error on iOS...