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

255
Visualizações
How to save an image that is assigned to a certain document

I am trying to build a post system, similar to instagram's, where a user has the chance to upload a image or video that is then saved within a certain document's mediaURL field. The problem is: I want to display the image first to the user himself in the post form. Therefore I need to store the image first, the question is under what name should it be saved?

Normally I would create a post with an auto-generated ID and then save the image under that ID. I assume that there would be a better way that I could maybe generate an idea, that could then be given to save the post itself.

const post = await addDoc(collection(db, "posts"), {
    text : text,
    mediaURL : "",
    author : currentUser.uid,
    createdAt : firebase.firestore.FieldValue.serverTimestamp(),
    likes : []
})


const fileRef = ref(storage, post.id); 
const snapshot = await uploadBytes(fileRef, file);
const mediaURL = await getDownloadURL(fileRef);


const userRef = doc(db, "users", currentUser.uid)

await updateDoc(userRef, {
    posts : arrayUnion(post.id)
})


const postRef = doc(db, "posts", post.id)

await updateDoc(postRef, {
    mediaURL : mediaURL
})

Given the problem that I need to upload the image first, creating an empty post, that might exist for longer might be a problem. So under what name can I save the file?

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