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

258
Vistas
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 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