无法将pdf文件转换为android pie中的base64
,文件路径返回的是“content://com.android.providers.downloads.documents/document/4402”,这不是真正的路径因此unable to access the file
。
不鼓励支持file:///path
uris,后来又放弃了。
您需要使用ContentResolver
访问content://auth/path
uri。
试试这个
fun convertToBase64(attachment: File): String {
return Base64.encodeToString(attachment.readBytes(), Base64.NO_WRAP)
}
我们可以将以下整个类用于我们的项目以获得真正的路径,我得到了解决我的问题的方法
之后,我使用以下代码将pdf文件转换为编码为base64字符串
fun convertToBase64(attachment: File): String {
return Base64.encodeToString(attachment.readBytes(), Base64.NO_WRAP)
}