Accessing Images from Firebase Storage in React Native

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 27

  • @bilalawad8937
    @bilalawad8937 2 роки тому +3

    Thank you sooooooooooo much, others were making it harder by using fileReader, this is 10x easier thank you! PS, i use react but i am learning react-native which is why i needed this!

  • @gtasa0629
    @gtasa0629 Рік тому +1

    Thank you so much! I have been searching for this a long time....
    Thank you Once again!

  • @gokulkrishna.s5691
    @gokulkrishna.s5691 2 роки тому +1

    Thank helpfull video😍

  • @mucadush3363
    @mucadush3363 2 роки тому

    i love your energy omg

  • @microsoftus-eu5323
    @microsoftus-eu5323 2 роки тому

    U deserve the world ❤

  • @alaamer7303
    @alaamer7303 Рік тому

    thanks

  • @mucadush3363
    @mucadush3363 2 роки тому

    bro i love you THANK YOU

  • @gtasa0629
    @gtasa0629 Рік тому +1

    Hello Please put a video on how to edit metadata on firebase storage in react native

  • @gtasa0629
    @gtasa0629 Рік тому +1

    Please teach us everything about firebase react native expo please!😘

  • @talbertherndon1925
    @talbertherndon1925 2 роки тому

    Thank you much needed ❤️

  • @810886
    @810886 2 роки тому

    Thanks! This really helps a lot!!!

  • @mamadouseck3612
    @mamadouseck3612 2 роки тому

    Thanks

  • @joshuaborseth
    @joshuaborseth 2 роки тому +1

    thanks for your help!! you explain stuff very well!

  • @sohailpanchoo848
    @sohailpanchoo848 2 роки тому

    thank you soooooooooooooooooooooooooooooooooooooooooooooooo much you helped me a lot i was really stuck

  • @abdul-samadnasir3318
    @abdul-samadnasir3318 2 роки тому

    Please do you how to display data from firestore to a pie chart

    • @the_whiz
      @the_whiz  2 роки тому

      1. get the data from firestore
      2. store data into state
      3. create the pie chart with data from the state variable
      you can reference this person's github for a good example: github.com/Eesha-Jain/PollYourOwn/blob/main/screens/TabTwoScreen.tsx

  • @kingogamer4358
    @kingogamer4358 2 роки тому

    I have tried the same pattern but i donot get the url

  • @brnbk8910
    @brnbk8910 2 роки тому

    I need to render in my app the image that is in the firestore, the url is already there, I want to send an image from my gallery, I want it to go to the firestore, and store the url there, and with this url render in my application,
    HELP ME

    • @the_whiz
      @the_whiz  2 роки тому

      maybe try this: www.themobileentity.com/home/how-to-load-image-from-url-in-react-native

  • @akshatsrivastav9911
    @akshatsrivastav9911 2 роки тому

    hey could you help me out with this ,
    const uploadPost = async () => {
    setRequestRunning(true);
    const response = await fetch(uri);
    const bloob = await getBlobFromUri(uri);
    const storageRef = ref(storage, `hbdas/${user.user.uid}/${uuid()}}`);
    const uploadTask = uploadBytes(storageRef, bloob);
    await getDownloadURL(uploadTask).then((x) => {
    setUrl(x);
    console.log(x);
    });
    it just gets stuck and doesn't print the x

    • @the_whiz
      @the_whiz  2 роки тому

      I believe your in the storageReference creation line, you miswrote the location to the image. Look at my video for an example of how it should be done.

  • @rushikeshgodse1206
    @rushikeshgodse1206 2 роки тому +1

    but how could i get multiple images ??? just HOwwwwWWWWW PlzzzzzzzzzzzZZZZ

    • @the_whiz
      @the_whiz  2 роки тому

      you can iterate through an array to get multiple images or call this function many times

  • @cineverseproductions
    @cineverseproductions 2 роки тому

    Great and simple video BUT I have a question and a doubt. I am using ImagePicker from Expo like one of your previous videos, and if(!result.cancelled), I am setting an image on a useState hook variable like setImage(result.uri) which is fine, and my uploadImage() is uploading images with the blob and I can see the images being uploaded by a specific uid(probably my current logged in user) in my firebase storage. BUT now, when I try to retrieve it back like yours with useEffect, it's not showing me any image in my Image source. Code is pretty much the same BUT do you think, your *setUrl* hook variable is mine *setImage* in this case. Because in the source is {{ uri: image }} ? I have attached my code below.
    const [image, setImage] = useState("upload.wikipedia/commons/7/7c/Profile_avatar_placeholder_large.png");
    const pickImage = async () => {
    // No permissions request is necessary for launching the image library
    let result = await ImagePicker.launchImageLibraryAsync({
    mediaTypes: ImagePicker.MediaTypeOptions.All,
    allowsEditing: true,
    aspect: [4, 3],
    quality: 1,
    });
    if (!result.cancelled) {
    setImage(result.uri || url);
    uploadImage();
    }
    };
    const uploadImage = async () => {
    const blob = await new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest();
    xhr.onload = function() {
    resolve(xhr.response);
    }
    xhr.onerror = function(e) {
    reject(new TypeError("Network request failed"));
    };
    xhr.responseType = "blob";
    xhr.open("GET", image, true);
    xhr.send(null);
    });
    const ref = firebase
    .storage()
    .ref()
    .child(`${auth.currentUser.uid}/profile_pic.jpg`);
    const snapshot = await ref.put(blob);
    const remoteUri = await snapshot.ref.getDownloadURL()
    // when we're done sending it, close and release the blob
    blob.close();
    // return the result, eg. remote URI to the image
    return remoteUri;
    }
    useEffect(() => {
    const func = async () => {
    const storage = getStorage();
    const reference = ref(storage, `${auth.currentUser.uid}/profile_pic.jpg`);
    await getDownloadURL(reference).then(url => {
    setImage(url);
    })
    if(url == undefined) {
    func(); }
    }
    },[]);
    {image && }

    • @the_whiz
      @the_whiz  2 роки тому +1

      in your useEffect, after the function do you see the []? you need to put the image into that so it looks like useEffect(()=>{...}, [image]). This means that it will update the screen with the image.

    • @cineverseproductions
      @cineverseproductions 2 роки тому

      @@the_whiz Hi there. Thanks for getting back to me on this so quickly. I tried putting the image hook variable in [ ] useEffect in the end and try loading the app again, but the image is not loading and appearing in the url. The code is exactly the same to my above comment ☝️ but it's not working. I'm not sure what's wrong. Again, I will attach the useEffect code snippet below.
      useEffect(() => {
      const func = async () => {
      const storage = getStorage();
      const reference = ref(storage, `${auth.currentUser.uid}/profile_pic.jpg`);
      await getDownloadURL(reference).then(url => {
      console.log(url);
      setImage(url);
      })
      if(url == undefined || null) {
      func(); }
      }
      },[image]);

    • @the_whiz
      @the_whiz  2 роки тому

      @@cineverseproductions I still think it's an issue with the dynamic updating. nkaushik.com/react-native/dynamic-image-source-in-react-native/ maybe try this?