Profile image not showing after saving(it just shows blank white screen)

前端 未结 3 1031
挽巷
挽巷 2020-12-12 04:54

I am trying to upload user profile image and store in firebase.My image successfully stores in firebase storage and in the user database.

When I upload the image it

相关标签:
3条回答
  • 2020-12-12 05:30

    This is the function in which I updated the imagePath listener code which works fine now-

    private fun saveUserInformation(){
            mName=mNameField.text.toString()
            mPhone=mPhoneField.text.toString()
            val userInfo=HashMap<String,Any>()
            userInfo.put("name",mName)
            userInfo.put("phone",mPhone)
            mCustomerDatabase.updateChildren(userInfo)
            if(resultUri!=null){
                val imagePath:StorageReference=mStorage.child("customer_profile_image").child(userId).child(resultUri.lastPathSegment )
                val uploadTask:UploadTask=imagePath.putFile(resultUri)
    
                uploadTask.addOnSuccessListener(OnSuccessListener <UploadTask.TaskSnapshot>(){taskSnapshot->
    
     //*********************This is the upadated part of code                   imagePath.downloadUrl.addOnSuccessListener(OnSuccessListener<Uri>{resultUri->
                            val downloadUrl=resultUri.toString()
                            val newImage= HashMap<String,Any>()
                            newImage["profileImageUrl"] = downloadUrl
                            mCustomerDatabase.updateChildren(newImage)
                        }).addOnFailureListener(OnFailureListener() {
                            Toast.makeText(this,"Profile image not",Toast.LENGTH_SHORT).show()
                        })
    //*******************************************************************************
    
    
                }).addOnFailureListener(OnFailureListener() {
                    Toast.makeText(this,"Profile image not uploaded",Toast.LENGTH_SHORT).show()
                })
            }
            finish()
        }

    0 讨论(0)
  • 2020-12-12 05:32

    You are getting the following error:

    Load failed for com.google.android.gms.tasks.zzu@c0645c1

    Because you are trying to display an image that does not exist. As I see in your database, the profileImageUrl property holds an image url that is not valid.

    See the red line? What it actually holds is the address of an object from the memory and not an image url. This is happening because you are calling toString() method on the downloadUrl object. So the way you are get the donwload url is not correct. This is the correct way for getting the url. Once you get url of the image and you add it to the database and everything will work as expected.

    0 讨论(0)
  • 2020-12-12 05:34

    I also had this problem and solved the problem as follows

    RequestOptions options = new RequestOptions()
           .fitCenter()
           .error(errorImageDrawble)
           .diskCacheStrategy(DiskCacheStrategy.ALL)
           .priority(priority.HIGH);
    
    Glide
         .with(applicationContext)
         .load(mProfileImageUrl)
         .apply(options)
         .into(mProfileImage);
    
    0 讨论(0)
提交回复
热议问题