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:
@@ -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?,
|
||||
|
||||
Reference in New Issue
Block a user