将PDF文件上传到Firebase

时间:2018-08-10 14:23:58

标签: android firebase firebase-realtime-database kotlin

我正在将PDF文件从手机存储上传到Firebase存储。 有一个EditText视图,用于添加名称并将其上传到Firebase数据库。我只想显示Firebase存储下载URL和Firebase数据库中的这个名称。下面是代码,请指导我所缺少的内容。名称和URL的代码。代码是科特林语言。

Upload()是一个类对象

 val upload = Upload(txtPdfName.text.toString().trim(), taskSnapshot?.downloadUrl.toString().trim())

val uploadId = mDatabaseRef.push().key
mDatabaseRef.child(uploadId).setValue(upload)

这是上载课程的代码。

class Upload(toString: String, toString1: String) {
    var name : String = ""
    var url : String = ""



    companion object {
        fun getName(upload: Upload): String {
            return upload.name
        }
        fun getUrl(upload: Upload): String{
            return upload.url
        }
    }

    fun Upload(name: String, url: String) {
        this.name = name
        this.url = url
    }


}

这是名称和URL值为空的数据库图片。

enter image description here

Alex Mamo这是我正在使用的功能。

 fun upload_Files(view: View) {
        if (true) {
            val dialoq = ProgressDialog(this)
            dialoq.setTitle("File is Uploading")
            dialoq.show()

            val ref = mStorageRef.child(FB_STORAGE_PATH + System.currentTimeMillis() + "." + getImageTxt(uripdf))
            try {
                ref.putFile(uripdf).addOnSuccessListener { taskSnapshot: UploadTask.TaskSnapshot? ->
                    dialoq.dismiss()
                    Toast.makeText(this, "Successfully Uploaded :)", Toast.LENGTH_LONG).show()
                    val upload = Upload(txtPdfName.text.toString().trim(), taskSnapshot?.downloadUrl.toString().trim())

                    val uploadId = mDatabaseRef.push().key
                    mDatabaseRef.child(uploadId).setValue(upload)

                 Log.i("Data",upload.toString())
                }

0 个答案:

没有答案