Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Firestore upload 2 images

Hello I would like to upload 2 images as jpg, but I can't get the format correct, and it would only upload one picture.


  const [badge, onBadgeChange] = useState('/');
  const [image, setImage] = useState('/');


  const addCompetition = async() =>{
    await handleImageUpload()
   
}


  const handleImageUpload = async() =>{
    const imagebanner = ref(storage, 'images/'+ title+'banner'+ Timestamp.fromDate(new Date()) + ".jpg" )
    const imagebadge = ref(storage, 'images/'+ title+'badge'+ Timestamp.fromDate(new Date()) + ".jpg" )
    
    const blob = await new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest();
        xhr.onload = function () {
          resolve(xhr.response);
        };
        xhr.onerror = function (e) {
          console.log(e);
          reject(new TypeError("Network request failed"));
        };
        xhr.responseType = "blob";
        xhr.open("GET", image, true);
        xhr.send(null);
    });





      await uploadBytes(imagebanner, blob).then((snapshot) => {
        getDownloadURL(snapshot.ref).then((url) => {
            console.log(url)
            createCompetition({ title: title,
              description:description,
              venue:venue,
              age:age,
              gender:gender,
              rank:rank,
              date:date,
              dateCreated : Timestamp.fromDate(new Date()),
              maxplayers:maxplayers,
              hole:hole,
              badge:badge,
              image:image})
        })
        .catch((error) => console.log(error))
    })
    .catch((error) => console.log(error))
    // We're done with the blob, close and release it
    blob.close();
    navigation.pop();
    }



  

  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,
    });

    console.log(result);

    if (!result.cancelled) {
      setImage(result.uri);
    }
  };

  const pickImage2 = 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,
    });

    console.log(result);

    if (!result.cancelled) {
      onBadgeChange(result.uri);
    }
  };

This code above works for one image but I can't get it to also upload imagebadge, I am new to firebase so I have tried xhr.open("GET", {image, badge}, true) but that only made the one image that did upload to an octet image and not jpg anymore.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda