feat: enhance message encryption and media file conversion with improved compression and base64 encoding
This commit is contained in:
@@ -165,15 +165,16 @@ object MediaUtils {
|
||||
*/
|
||||
suspend fun uriToBase64File(context: Context, uri: Uri): String? = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
|
||||
val inputStream = context.contentResolver.openInputStream(uri)
|
||||
|
||||
val inputStream = context.contentResolver.openInputStream(uri)
|
||||
?: return@withContext null
|
||||
|
||||
|
||||
val bytes = inputStream.readBytes()
|
||||
inputStream.close()
|
||||
|
||||
val base64 = Base64.encodeToString(bytes, Base64.NO_WRAP)
|
||||
|
||||
|
||||
val mimeType = context.contentResolver.getType(uri) ?: "application/octet-stream"
|
||||
val base64 = "data:$mimeType;base64," + Base64.encodeToString(bytes, Base64.NO_WRAP)
|
||||
|
||||
base64
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
|
||||
Reference in New Issue
Block a user