I'm doing a project with Angular 6 and Cloud Firestore, which consists of adding products. I have defined an interface with the attributes that must be carried, and when I receive them from a form, I manage them with the service:
addProduct(idDepartament: string, product: Product, image: File) { const id = this.db.createId(); const document = this.db.doc('departaments/${idDepartament}/products/${id}'); // Aquí sí presiste el ID del producto product.id = id; if (image) { // Si existe la imagen, entonces la guardará en Firebase Storage const path = 'images/${idDepartament}/${id}/${image.name}'; const ref = this.storage.ref(path); const task = this.storage.upload(path, image); task.snapshotChanges().pipe( finalize(() => { ref.getDownloadURL().subscribe((data: string) => { product.image = data; // Guarda la dirección donde se almacenó la imagen product.nameImage = image.name; // Guarda el nombre de la imagen }); })).subscribe(); } else { // Si no hay imagen, tendrá una por defecto product.image = './assets/img/noImage.png'; } // Retorna una promesa para mostrar si todo salió bien, o hubo un problema en la subida del archivo return document.set(product); }
I think everything is fine, however, when testing it does not save nameImage
or image
in product
. And I verified that if they appear in the object:
Objecto product
What happens? It seems that he is saving it correctly. However, the two attributes for the image are not found in the Database: Archive in Firebase
Thanks. I hope you can clarify this strange event, because a couple of days ago it worked well, and now you do not want to store those two attributes.