0

I have use this code:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

    super.onActivityResult(requestCode, resultCode, data)
    if (resultCode == Activity.RESULT_OK && requestCode == PICTURE_RESULT) {
        if (data != null) {

            val imageUri: Uri = data.data!!
            val ref: StorageReference = FirebaseUtil.storageRef!!.child(imageUri.lastPathSegment!!)

            // Another implementation
            // UploadTask uploadTask = ref.putFile(imageUrl)
            ref.putFile(imageUri).addOnSuccessListener(this) {
                ref.downloadUrl.addOnCompleteListener(this) { task ->
                    val url = task.result.toString()
                    deal!!.imageUrl = url
                }
            }


        } else {
            Log.d("IMAGE", resultCode.toString())
            Toast.makeText(this, "Upload failure", Toast.LENGTH_LONG).show()
        }

    }

    finish()
}

And also use this code:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

    super.onActivityResult(requestCode, resultCode, data)
    if (resultCode == Activity.RESULT_OK && requestCode == PICTURE_RESULT ) 
    {
        if (data != null) {

            val imageUri : Uri = data.data!!
            val ref : StorageReference = FirebaseUtil.storageRef!!.child(imageUri.lastPathSegment!!)

            // Another implementation
            // UploadTask uploadTask = ref.putFile(imageUrl)
            ref.putFile(imageUri).addOnSuccessListener(this, object : OnSuccessListener<UploadTask.TaskSnapshot> {
                override fun onSuccess(taskSnapshot : UploadTask.TaskSnapshot?) {
                    val url : String = taskSnapshot!!.storage.downloadUrl.toString()
                    deal!!.imageUrl = url
                }
            })

        } else {
            Log.d("IMAGE", resultCode.toString())
            Toast.makeText(this, "Upload failure", Toast.LENGTH_LONG).show()
        }

    }
}

I can see the URI from my Android debug window but that isn't been set in the firebase item as I want it to, I am using the latest firebase latest database library. I can see this value in the debug window of Android studio. but that value is not used to set the image for my firebase entry. Libraries that I am using:

implementation 'com.google.firebase:firebase-database:18.0.1'
implementation 'com.google.firebase:firebase-storage:18.1.1'
implementation 'com.firebaseui:firebase-ui-database:4.0.0
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
George Udosen
  • 906
  • 1
  • 13
  • 28

0 Answers0