0

I created an app and I want to store some images in a Firebase Storage, this is working fine, those images are uploaded, but I want to save their path in the database and those values are not inserted.

Let me show you what I did:

I'm not showing you the entire function. Only the code that points to my problem.

List<String> picturesUrls = new ArrayList<String>(); //This is declared globaly

 buttonSigningUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                uploadFile(mProfilePic,"profilePicture");
                uploadFile(mIdPhoto,"idPicture");
                uploadFile(mCriminalRecord,"criminalRecordPicture");
                final List<String> pictureUrls = picturesUrls;

                mFirebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(task.isSuccessful()) {
                            final CarrierUser carrierUser;
                            carrierUser = new CarrierUser(

                                    pictureUrls

                            );
                            FirebaseDatabase.getInstance().getReference("User")
                                    .child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(carrierUser).addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task) {
                                    if(task.isSuccessful()) {
                                        Toast.makeText(SignupCarrier.this,"Your request has been sent for approval", Toast.LENGTH_LONG).show();
                                        sendEmail(email, fullname);
                                        openLogin();

                                    }
                                }
                            });
                        }
                    }
                });



            }
        });

Upload File Function :

private void uploadFile(Uri path,String forWho) {

        if(path != null) {

            StorageReference fileReference = mStorageRef.child(editemail.getText().toString()+"-"+forWho+"-"+System.currentTimeMillis()+"."+getFileExtension(path));
            mUploadTask = fileReference.putFile(path)
                    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                          picturesUrls.add(taskSnapshot.getUploadSessionUri().toString());
                        }
                    })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(SignupCarrier.this, e.getMessage(),Toast.LENGTH_LONG).show();
                }
            });
        }

    }

And the Object:



import java.util.List;

public class CarrierUser {

    public List<String> picturesUrls;


    public CarrierUser() {

    }

    public CarrierUser(List<String> picturesUrls) {
        this.picturesUrls = picturesUrls;
    }
}

I do have another values and fields, but they are inserted, only this list with paths is not. Maybe I did something wrong when I add a path to that list, but I can't figure out what exactly is wrong. Can you please help me out? Thank you very much.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Calin Onaca
  • 175
  • 3
  • 14

0 Answers0