Get mime type from extension if mime type in response header is null for a application/octet-stream content type

This commit is contained in:
David Kaspar
2025-03-15 12:13:46 +00:00
parent c1399d129e
commit e6c413b176
@@ -43,6 +43,7 @@ import okio.IOException
import okio.buffer
import okio.sink
import okio.source
import okio.use
import java.io.File
import java.util.UUID
@@ -124,8 +125,8 @@ object MediaSaverToDisk {
checkNotNull(contentType) { "Can't find out the content type" }
val realType =
if (mimeType != null && contentType == "application/octet-stream") {
mimeType
if (contentType == "application/octet-stream") {
mimeType ?: getMimeTypeFromExtension(url)
} else {
contentType
}
@@ -154,6 +155,11 @@ object MediaSaverToDisk {
)
}
private fun getMimeTypeFromExtension(fileName: String): String =
fileName.substringAfterLast('.', "").lowercase().let {
MimeTypeMap.getSingleton().getMimeTypeFromExtension(it).orEmpty()
}
fun save(
localFile: File,
mimeType: String?,