Skip to content

Commit d492b43

Browse files
committed
fix: sometimes mime type is null. Use a default if so
1 parent e1225e0 commit d492b43

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/kotlin/com/ctrlhub/core/media/ImagesRouter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import io.ktor.client.plugins.ClientRequestException
1616
import io.ktor.http.ContentType
1717
import io.ktor.http.HttpStatusCode
1818
import java.io.File
19+
import java.net.URLConnection
1920
import java.nio.file.Files
2021
import kotlin.io.encoding.Base64
2122
import kotlin.io.encoding.ExperimentalEncodingApi
@@ -93,7 +94,8 @@ class ImagesRouter(httpClient: HttpClient): Router(httpClient) {
9394

9495
return try {
9596
val bytes = image.readBytes()
96-
val mimeType = Files.probeContentType(image.toPath())
97+
val mimeType = URLConnection.guessContentTypeFromName(image.name)
98+
?: "image/png"
9799
val base64Data = Base64.encode(bytes)
98100
val dataUri = "data:$mimeType;base64,$base64Data"
99101

0 commit comments

Comments
 (0)