Query insert firebase data

0

I want to add an image plus the following attributes, names, category, phone, address, etc in the storage firebase, I already have the registration and the insertion of an attribute but I do not know how to save the following attributes to my firebase. This is my code.

if (imgUri != null) {
        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setTitle("registrando imagen");
        dialog.show();
        //Get the storage reference
        StorageReference ref = mStorageRef.child(FB_STORAGE_PATH + System.currentTimeMillis() + "." + getImageExt(imgUri));

        //Add file to reference

        ref.putFile(imgUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {


                String nombreRest=nombre.getText().toString();
                String telefono= numero.getText().toString();
                String description2= direccion.getText().toString();

                Restaurante imageUpload = new Restaurante(nombreRest,taskSnapshot.getDownloadUrl().toString());



                //Save image info in to firebase database
                String uploadId = mDatabaseRef.push().getKey();
                mDatabaseRef.child(nombreRest).setValue(imageUpload);
                mDatabaseRef.child("Telefono").setValue(telefono);
                mDatabaseRef.child("categoria").setValue(cate);
                mDatabaseRef.child("horario").setValue(horario2);
                mDatabaseRef.child("direccion").setValue(description2);

                //Dimiss dialog when success
                dialog.dismiss();
                //Display success toast msg
                Toast.makeText(getApplicationContext(), "Imagen registrada", Toast.LENGTH_SHORT).show();




            }
        })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {

                        //Dimiss dialog when error
                        dialog.dismiss();
                        //Display err toast msg
                        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                })
                .addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {

                    @Override
                    public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {

                        //Show upload progress

                        double progress = (100 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
                        dialog.setMessage("Uploaded " + (int) progress + "%");
                    }
                });
    } else {
        Toast.makeText(getApplicationContext(), "Please select image", Toast.LENGTH_SHORT).show();
    }

here I leave a photo to understand me

    
asked by Deyvis Garcia Cercado 06.06.2018 в 06:25
source

1 answer

0

This is the part where you are failing. you must make a reference to the new key that you created with push, and just add the data.

    //Save image info in to firebase database
    String uploadId = mDatabaseRef.push().getKey();
    // en esta parte no se que quieras hacer, la key es el nombre del restaurant,
    // y tiene como datos el mismo nombre
    mDatabaseRef.child(uploadId).child(nombreRest).setValue(imageUpload);

    //Quizas puedas hacer de esta forma, para que solo se guarde el nombre y url, 
    //no que se anide otra vez como esta dentro del nombre del restaurant
    //mDatabaseRef.child(uploadId).setValue(imageUpload);

     mDatabaseRef.child(uploadId).child("Telefono").setValue(telefono);
     mDatabaseRef.child(uploadId).child("categoria").setValue(cate);
     mDatabaseRef.child(uploadId).child("horario").setValue(horario2);
     mDatabaseRef.child(uploadId).child("direccion").setValue(description2);
    
answered by 06.06.2018 в 22:38