0

In-app image was selected but when I click to upload on the firebase button that time this error came???

select image button:

public void uploadImage(){

    StorageReference storageReference = FirebaseStorage.getInstance ()
            .getReference ().child ( "ProductImage" ).child ( uri.getLastPathSegment () );
    storageReference.putFile ( uri ).addOnSuccessListener ( new OnSuccessListener <UploadTask.TaskSnapshot> ( ) {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

            Task <Uri> uriTask = taskSnapshot.getStorage().getDownloadUrl();
            
            //Error comes on this line in a while- loop code.

            while(!uriTask.isComplete ());
            Uri urlImage = uriTask.getResult ();
            imageUrl = urlImage.toString ();[![enter image description here][1]][1]

        }
    } ).addOnFailureListener ( new OnFailureListener ( ) {
        @Override
        public void onFailure(@NonNull Exception e) {
            Toast.makeText ( Add.this, e.getMessage (), Toast.LENGTH_SHORT ).show ( );
        }
    } );
}
Somesh
  • 23
  • 6
  • It's hard to help with an error without seeing the original error message. General descriptions or paraphrasings of the message are not usually helpful. Please edit your post to include the _exact_ wording of any error messages, including the full [stack trace](/a/23353174) of any exceptions, if applicable, as well as which line of code the stack trace points to. Please see [ask] and [How to create a Minimal, Reproducible Example](/help/minimal-reproducible-example) – Ryan M Aug 01 '20 at 07:54

1 Answers1

1

Try this method for uploading image to firebase storage and

Make sure to set up storage rules accordingly ---

if you're authentication user first then use

if request.auth != null;

OR --

if you're not authentication user first then use

if request.auth == null;
Harsh Suvagiya
  • 131
  • 1
  • 3