send works
This commit is contained in:
@@ -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(),
|
||||
size = bytes.size.toULong(),
|
||||
thumbnailInfo = null,
|
||||
thumbnailSource = null,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
tempFile.delete()
|
||||
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("SendFile", "Failed to send file", e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user