How to make firebase image path work as an image on different devices on React Native?


I have a function that requests the user for an image from their phone. Once this is given, the path is uploaded to firebase and looks something like this:


The problem is that on the attempt to display it only displays on the phone that this image has been uploaded on, since other devices do not possess this image.

How can I convert the firebase path/image into an image that is displayable in all phones, even though this image does not exist on all users devices?

Here is some important bits of code:

function that gets the library image

const addImage = async () => {
    let image = await ImagePicker.launchImageLibraryAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.Images,
      allowsEditing: true,
      aspect: [4, 3],
      quality: 1,
    if (!image.cancelled) {

function that adds the image to firebase:

  const createPhoto = async () => {
    await db
      .then(() => {
      .catch(error => alert(error));

Jsx that displays the image:

     source={{ uri: galleryImage }}
     onLoadStart={() => setIsLoading(true)}
     onLoadEnd={() => setIsLoading(false)}

Any help is appreciated


This is because, you are saving the local path of the image, hence it can not be displayed on other phones. You need to upload the image to a storage bucket and save the URL of that image on the db.

Convert image to blob

const blob = await new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest();
    xhr.onload = function() {
    xhr.onerror = function() {
        reject(new TypeError("Network request failed"));
    xhr.responseType = "blob";
    // image.uri is the local path of the image on the device"GET", image.uri, true);

Upload image to storage

const storageRef = ref(storage, `profile-pictures/${userContext.user.uid}/${name}`);
const task = uploadBytesResumable(storageRef, blob)
task.on('state_changed', (snapshot) => {
    const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100
}, (err) => {
}, () => {
    .then((downloadURL) => {
        // image successfully uploaded, save "downloadURL" in your db

Answered By – Aakash Rathee

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published