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

159
Visualizações
Cannot upload id by using uuid on firebase with React.js

Here is my function on JS, the issue is uuid would be saved as text like photos below by using .ref('posts/${id}')

According to photo 3, the uuid is working correctly, so I assume that there are some simple code mistakes on my "sendPost".

If you are good at JS and this type of issue, that would be grateful to be indicated.

import { v4 as uuid } from 'uuid';

const sendPost = () => {
    const id = uuid();
    const uploadTask = storage
      // eslint-disable-next-line no-template-curly-in-string
      .ref('posts/${id}')
      .putString(cameraImage, "data_url");

    uploadTask.on(
      "state_changed",
      null,
      (error) => {
        //error func
        console.log(error);
      },
      () => {
        //Complete func
        storage
          .ref("posts")
          .child(id)
          .getDownloadURL()
          .then((url) => {
            db.collection("posts").add({
              imageUrl: url,
              username: "TEST",
              read: false,
              //profile picture
              timstamp: firebase.firestore.FieldValue.serverTimestamp(),
            });
            history.replace("/chats");
          });
      }
    );
  };

firebase inside photo

uuid working check photo

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This ${id} in this code is just a string:

const uploadTask = storage
  // eslint-disable-next-line no-template-curly-in-string
  .ref('posts/${id}')

The no-template-curly-in-string actually says exactly what is going on: a string in '' cannot contain so-called template variables like {$id}. Or well, it can contain that string, but JavaScript will not replace that with the value of id.


If you want the ${id} to be interpreted as the value of the id variable, using backticks around the string instead of quotes:

const uploadTask = storage
  .ref(`posts/${id}`)

Alternatively, you can use classic string concatenation:

const uploadTask = storage
  .ref('posts/'+id)

Or use Firebase's child() function:

const uploadTask = storage
  .ref('posts').child(id)
about 4 years ago · Juan Pablo Isaza Relatório
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