Kotlin-从Firebase存储下载图像的URL

时间:2020-02-19 07:42:27

标签: android firebase kotlin firebase-storage

我在从 firebase 存储中下载基本邮件应用程序的URL时遇到问题,到目前为止,这是我的进度,但是我相信我正在尝试使用过时的依赖项,并且不确定如何解决此问题因为我是 kotlin 的新手。

createSnapImageView?.isDrawingCacheEnabled = true
        createSnapImageView?.buildDrawingCache()
        val bitmap = (createSnapImageView?.drawable as BitmapDrawable).bitmap
        val baos = ByteArrayOutputStream()
        bitmap?.compress(Bitmap.CompressFormat.JPEG, 100, baos)
        val data = baos.toByteArray()

        var uploadTask =
            FirebaseStorage.getInstance().reference.child("images").child(imageName)
                .putBytes(data)
        uploadTask
            .addOnFailureListener {
                // Handle unsuccessful uploads
                Toast.makeText(this, "Upload Failed", Toast.LENGTH_SHORT).show()
            }
            .addOnSuccessListener(OnSuccessListener<UploadTask.TaskSnapshot>
            { taskSnapshot ->
                // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
                val downloadUrl = taskSnapshot.metadata?.reference?.downloadUrl
                val intent = Intent(this, ChooseUserActivity::class.java)
                intent.putExtra("imageURL", downloadUrl.toString())
                intent.putExtra("imageName", imageName)
                intent.putExtra("message", messageEditText?.text.toString())
                startActivity(intent)
            }).addOnSuccessListener {
                OnSuccessListener<UploadTask.TaskSnapshot> {
                }
            }

0 个答案:

没有答案