Dirty hack to fix mime-type for webps

This commit is contained in:
DerEchteJoghurt 2021-09-20 13:28:54 +02:00
parent 6c29d90503
commit a4efa03dce

View file

@ -14,10 +14,19 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import java.nio.file.Files;
import java.util.Optional;
public class Utils {
public static Optional<String> getExtensionByStringHandling(String filename) {
return Optional.ofNullable(filename)
.filter(f -> f.contains("."))
.map(f -> f.substring(filename.lastIndexOf(".") + 1));
}
public static String getFileMimeType(File file, String defaultMimeType) throws IOException {
if (getExtensionByStringHandling(file.toPath().toString()).get().equals("webp")) {
return "image/webp";
}
var mime = Files.probeContentType(file.toPath());
if (mime == null) {
try (InputStream bufferedStream = new BufferedInputStream(new FileInputStream(file))) {