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.buffer
|
||||||
import okio.sink
|
import okio.sink
|
||||||
import okio.source
|
import okio.source
|
||||||
|
import okio.use
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
@@ -124,8 +125,8 @@ object MediaSaverToDisk {
|
|||||||
checkNotNull(contentType) { "Can't find out the content type" }
|
checkNotNull(contentType) { "Can't find out the content type" }
|
||||||
|
|
||||||
val realType =
|
val realType =
|
||||||
if (mimeType != null && contentType == "application/octet-stream") {
|
if (contentType == "application/octet-stream") {
|
||||||
mimeType
|
mimeType ?: getMimeTypeFromExtension(url)
|
||||||
} else {
|
} else {
|
||||||
contentType
|
contentType
|
||||||
}
|
}
|
||||||
@@ -154,6 +155,11 @@ object MediaSaverToDisk {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getMimeTypeFromExtension(fileName: String): String =
|
||||||
|
fileName.substringAfterLast('.', "").lowercase().let {
|
||||||
|
MimeTypeMap.getSingleton().getMimeTypeFromExtension(it).orEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
fun save(
|
fun save(
|
||||||
localFile: File,
|
localFile: File,
|
||||||
mimeType: String?,
|
mimeType: String?,
|
||||||
|
|||||||
Reference in New Issue
Block a user