Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

121
Vistas
Uploading file to firebase storage results in null

I am trying to upload selected image from my phone, using ImagePicker library:

const [bookName, setBookName] = useState("");
const [bookAuthor, setBookAuthor] = useState("");
const [selectedPhoto, setSelectedPhoto] = useState();

const selectPhoto = async () => {
  let permissionResult = await ImagePicker.requestMediaLibraryPermissionsAsync();
  if (permissionResult.granted === false) {
    Alert.alert("Permission to access camera roll is required!");
    return;
  }

  let pickerResult = await ImagePicker.launchImageLibraryAsync();

  if (pickerResult.cancelled === true) {
    return;
  }

  setSelectedPhoto(pickerResult);
};

const uploadBook = async () => {
  if (selectedPhoto && bookName !== "" && bookAuthor !== "") {
    const storage = getStorage();
    const uploadUri = Platform.OS === 'ios' ? selectedPhoto.uri.replace('file://', '') : selectedPhoto.uri;

    let bookKey = push(ref(db, 'books/'), {
      name: bookName,
      author: bookAuthor,
      label: '',
    }).key;

    const booksRef = sRef(storage, "books/" + bookKey + '.jpg');
    await uploadBytes(booksRef, uploadUri).then(() => {
      update(ref(db, 'books/' + bookKey), {
        name: bookName,
        author: bookAuthor,
        label: bookKey + '.jpg',
      })
    });
  }
};

Everything working fine, except uploading files. I got file in the storage, which content is 'undefined'. So, how to upload files properly?

P.S. The file is actually available, as I display it after picking

<Image source={{ uri: selectedPhoto.uri }} style={{ width: "100%", height: "100%", resizeMode: "contain" }} />
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you check the documentation for uploadBytes it accepts: Blob | Uint8Array | ArrayBuffer. So it doesn't expect a URL/string value.

You'll want to either create a Blob reference to the selected file, or read the bytes from that file and pass them to Firebase as an ArrayBuffer.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda