图像在Firebase Storage上上传了4次

时间:2019-06-22 03:12:28

标签: image firebase kotlin firebase-storage

我遇到了一个问题,不知道根本原因在哪里。 当我将图像上传到Firebase Storage时,它被上传了4次,我不知道为什么? 这是我的代码:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == ALEGE_POZA
            && resultCode == Activity.RESULT_OK) {
            selectedPhotoUri = data!!.data
            alertDialog.show()
            uploadFile()
                alertDialog.dismiss()
}
}

private fun uploadFile() {

        if (selectedPhotoUri == null) return
  var filename = UUID.randomUUID().toString()
        var reff = FirebaseStorage.getInstance().reference.child("/pozeBlog/$filename")
        var bitearrayoutstr:ByteArrayOutputStream=ByteArrayOutputStream()
        var uritobtm:Bitmap=MediaStore.Images.Media.getBitmap(context!!.contentResolver, selectedPhotoUri)
        uritobtm.compress(Bitmap.CompressFormat.JPEG,50,bitearrayoutstr )

        val data =bitearrayoutstr.toByteArray()

        reff.putBytes(data)
            .addOnSuccessListener {
                if (it != null) {
                    reff.downloadUrl.addOnCompleteListener { task: Task<Uri> ->
                        if (task.isSuccessful) {

                            var url = task.result.toString()

                          mDb!!.child("poze").push().setValue(url)

                            if (pozapost != null) {
                                Picasso.get().load(url).placeholder(R.drawable.logor).fit().centerCrop().into(pozapost)
                            } else {

                            }
                        }
                    }
                }
            }
    }

图片按2种尺寸上传4次2次: 例如:2张图片(135kb)和2张图片(155kb)

0 个答案:

没有答案