send works
This commit is contained in:
@@ -765,66 +765,29 @@ class MainViewModel(
|
|||||||
} else null
|
} else null
|
||||||
} ?: "file"
|
} ?: "file"
|
||||||
|
|
||||||
// Copy file to a temp path
|
val bytes = contentResolver.openInputStream(uri)?.use { it.readBytes() }
|
||||||
val tempFile = java.io.File(application.cacheDir, "upload_$fileName")
|
?: return@launch
|
||||||
contentResolver.openInputStream(uri)?.use { input ->
|
|
||||||
tempFile.outputStream().use { output -> input.copyTo(output) }
|
android.util.Log.d("SendFile", "fileName=$fileName mimeType=$mimeType bytes=${bytes.size}")
|
||||||
}
|
|
||||||
|
|
||||||
val params = UploadParameters(
|
val params = UploadParameters(
|
||||||
source = UploadSource.File(tempFile.absolutePath),
|
source = UploadSource.Data(bytes, fileName),
|
||||||
caption = null,
|
caption = null,
|
||||||
formattedCaption = null,
|
formattedCaption = null,
|
||||||
mentions = null,
|
mentions = null,
|
||||||
inReplyTo = 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(
|
timeline.sendFile(
|
||||||
params = params,
|
params = params,
|
||||||
fileInfo = org.matrix.rustcomponents.sdk.FileInfo(
|
fileInfo = org.matrix.rustcomponents.sdk.FileInfo(
|
||||||
mimetype = mimeType,
|
mimetype = mimeType,
|
||||||
size = tempFile.length().toULong(),
|
size = bytes.size.toULong(),
|
||||||
thumbnailInfo = null,
|
thumbnailInfo = null,
|
||||||
thumbnailSource = null,
|
thumbnailSource = null,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
tempFile.delete()
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
android.util.Log.e("SendFile", "Failed to send file", e)
|
android.util.Log.e("SendFile", "Failed to send file", e)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user