Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

Convert img to base64 kotlin android


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In your onActivityResult() you can use such way:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == RESULT_OK) {
            val documentFile: DocumentFile = DocumentFile.fromSingleUri(this, data!!.data!!)!!
            val string = data.data?.let { uri -> contentResolver.openInputStream(uri).use { it!!.readBytes() } }


            //Base64.encodeToString(string, Base64.NO_WRAP)

        }
    }

here:

Base64.encodeToString(string, Base64.NO_WRAP)

you can get your file encoded to Base64 string and process it. I hope that it will help you :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...