3

Has anyone experienced Expo go app for react native crashing when trying to upload image to Firebase store?

This issue started when I updated my iPhone to ios16. I can say the issue is with ios16 because on another iPhone and ipad with ios15.7 there is no crashing. There is also no crashing with all android phones.

My code is below just in case to check

useEffect(() => {
    const setImageFiles = async () => {
      setUploading(true);
      const timeStamp = new Date().toISOString();

      if (postImage1) {
        const firstFilename = await postImage1.substring(
          postImage1.lastIndexOf('/') + 1
        );
        const filenameFirsImage = timeStamp + firstFilename;
        setFirstImageFile(filenameFirsImage);
      } else {
        const secondFilename = await postImage2.substring(
          postImage2.lastIndexOf('/') + 1
        );
        const filenameSecondImage = timeStamp + secondFilename;
        setSecondImageFile(filenameSecondImage);
      }
      setUploading(false);
    };
    const unsubscribe = NetInfo.addEventListener((state) => {
      if (!state.isConnected) {
        setIsConnected(false);
        Alert.alert('Network Error!', 'You are not connected to the internet');
      }
    });
    setImageFiles();
    unsubscribe();
  }, []); 


const uploadImage1ToStore = async () => {
    setUploading(true);

    const blob = await new Promise((resolve, reject) => {
      const xhr = new XMLHttpRequest();
      xhr.onload = function () {
        resolve(xhr.response);
      };
      xhr.onerror = function () {
        reject(new TypeError('Network request failed'));
      };
      xhr.responseType = 'blob';
      xhr.open('GET', postImage1, true);
      xhr.send(null);
    });

    const ref = firebase.storage().ref().child(firstImageFile);
    const snapshot = ref.put(blob);

    snapshot.on(
      firebase.storage.TaskEvent.STATE_CHANGED,
      () => {},
      (error) => {
        setUploading(false);
        Alert.alert(error.message);
        blob.close();
        return;
      },
      () => {
        snapshot.snapshot.ref
          .getDownloadURL()
          .then((url) => {
            setPostImage1Url(url);
          })
          .catch((error) => {
            Alert.alert(error.message);
          });
        blob.close();
      }
    );
  };
Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
Oao
  • 121
  • 7

1 Answers1

0

I faced same issue when I try to upload image to firebase storage on ios simulator. I relized that on ios image size to high and it cause error.You can resize it with expo-image-manipulator

akdeniz
  • 1
  • 1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34012396) – Anonymous Mar 16 '23 at 08:34
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 16 '23 at 16:39