Send SVG images as files (#4595)
Since Android doesn't have support for SVG files we can't create a thumbnail or get the dimensions and other metadata needed for the `m.image` message type, so we need to send them as plain files
This commit is contained in:
parent
d53f0480c7
commit
f9c00ac99d
2 changed files with 6 additions and 1 deletions
|
|
@ -24,6 +24,7 @@ object MimeTypes {
|
|||
const val Jpeg = "image/jpeg"
|
||||
const val Gif = "image/gif"
|
||||
const val WebP = "image/webp"
|
||||
const val Svg = "image/svg+xml"
|
||||
|
||||
const val Videos = "video/*"
|
||||
const val Mp4 = "video/mp4"
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class AndroidMediaPreProcessor @Inject constructor(
|
|||
*/
|
||||
private const val IMAGE_SCALE_REF_SIZE = 640
|
||||
|
||||
private val notCompressibleImageTypes = listOf(MimeTypes.Gif, MimeTypes.WebP)
|
||||
private val notCompressibleImageTypes = listOf(MimeTypes.Gif, MimeTypes.WebP, MimeTypes.Svg)
|
||||
}
|
||||
|
||||
private val contentResolver = context.contentResolver
|
||||
|
|
@ -75,6 +75,10 @@ class AndroidMediaPreProcessor @Inject constructor(
|
|||
): Result<MediaUploadInfo> = withContext(coroutineDispatchers.computation) {
|
||||
runCatching {
|
||||
val result = when {
|
||||
// Special case for SVG, since Android can't read its metadata or create a thumbnail, it must be sent as a file
|
||||
mimeType == MimeTypes.Svg -> {
|
||||
processFile(uri, mimeType)
|
||||
}
|
||||
mimeType.isMimeTypeImage() -> {
|
||||
val shouldBeCompressed = compressIfPossible && mimeType !in notCompressibleImageTypes
|
||||
processImage(uri, mimeType, shouldBeCompressed)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue