From 1cd4486599647a51135d646d883a98c30f1b7c37 Mon Sep 17 00:00:00 2001 From: mrfluffy Date: Tue, 24 Feb 2026 23:00:28 +0000 Subject: [PATCH] send works --- .../ui/screens/main/MainViewModel.kt | 67 +++++-------------- 1 file changed, 15 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/com/example/fluffytrix/ui/screens/main/MainViewModel.kt b/app/src/main/java/com/example/fluffytrix/ui/screens/main/MainViewModel.kt index caae61a..09a64df 100644 --- a/app/src/main/java/com/example/fluffytrix/ui/screens/main/MainViewModel.kt +++ b/app/src/main/java/com/example/fluffytrix/ui/screens/main/MainViewModel.kt @@ -765,66 +765,29 @@ class MainViewModel( } else null } ?: "file" - // Copy file to a temp path - val tempFile = java.io.File(application.cacheDir, "upload_$fileName") - contentResolver.openInputStream(uri)?.use { input -> - tempFile.outputStream().use { output -> input.copyTo(output) } - } + val bytes = contentResolver.openInputStream(uri)?.use { it.readBytes() } + ?: return@launch + + android.util.Log.d("SendFile", "fileName=$fileName mimeType=$mimeType bytes=${bytes.size}") val params = UploadParameters( - source = UploadSource.File(tempFile.absolutePath), + source = UploadSource.Data(bytes, fileName), caption = null, formattedCaption = null, mentions = null, inReplyTo = null, ) - when { - mimeType.startsWith("image/") -> { - timeline.sendImage( - params = params, - thumbnailSource = null, - imageInfo = org.matrix.rustcomponents.sdk.ImageInfo( - width = null, - height = null, - mimetype = mimeType, - size = tempFile.length().toULong(), - thumbnailInfo = null, - thumbnailSource = null, - blurhash = null, - isAnimated = null, - ), - ) - } - mimeType.startsWith("video/") -> { - timeline.sendVideo( - params = params, - thumbnailSource = null, - videoInfo = org.matrix.rustcomponents.sdk.VideoInfo( - duration = null, - width = null, - height = null, - mimetype = mimeType, - size = tempFile.length().toULong(), - thumbnailInfo = null, - thumbnailSource = null, - blurhash = null, - ), - ) - } - else -> { - timeline.sendFile( - params = params, - fileInfo = org.matrix.rustcomponents.sdk.FileInfo( - mimetype = mimeType, - size = tempFile.length().toULong(), - thumbnailInfo = null, - thumbnailSource = null, - ), - ) - } - } - tempFile.delete() + timeline.sendFile( + params = params, + fileInfo = org.matrix.rustcomponents.sdk.FileInfo( + mimetype = mimeType, + size = bytes.size.toULong(), + thumbnailInfo = null, + thumbnailSource = null, + ), + ) + } catch (e: Exception) { android.util.Log.e("SendFile", "Failed to send file", e) }