From 995a926e350fe875a181aa428a4796be26ee88f1 Mon Sep 17 00:00:00 2001 From: sbplat <71648843+sbplat@users.noreply.github.com> Date: Sun, 24 Dec 2023 15:27:16 -0500 Subject: [PATCH] fix!: map BMP and TIFF extensions to the proper MIME types Remove the WBMP image format from PDF to Image --- .../api/converters/ConvertImgPDFController.java | 14 ++++---------- .../resources/templates/convert/pdf-to-img.html | 1 - 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java index 0064a3ab..f0c60b69 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertImgPDFController.java @@ -1,6 +1,7 @@ package stirling.software.SPDF.controller.api.converters; import java.io.IOException; +import java.net.URLConnection; import org.apache.pdfbox.rendering.ImageType; import org.slf4j.Logger; @@ -23,6 +24,7 @@ import stirling.software.SPDF.model.api.converters.ConvertToImageRequest; import stirling.software.SPDF.model.api.converters.ConvertToPdfRequest; import stirling.software.SPDF.utils.PdfUtils; import stirling.software.SPDF.utils.WebResponseUtils; + @RestController @RequestMapping("/api/v1/convert") @Tag(name = "Convert", description = "Convert APIs") @@ -89,15 +91,7 @@ public class ConvertImgPDFController { } private String getMediaType(String imageFormat) { - if (imageFormat.equalsIgnoreCase("PNG")) - return "image/png"; - else if (imageFormat.equalsIgnoreCase("JPEG") || imageFormat.equalsIgnoreCase("JPG")) - return "image/jpeg"; - else if (imageFormat.equalsIgnoreCase("GIF")) - return "image/gif"; - else - return "application/octet-stream"; + String mimeType = URLConnection.guessContentTypeFromName("." + imageFormat); + return mimeType.equals("null") ? "application/octet-stream" : mimeType; } - - } diff --git a/src/main/resources/templates/convert/pdf-to-img.html b/src/main/resources/templates/convert/pdf-to-img.html index 5d5a6ae7..d4d328d7 100644 --- a/src/main/resources/templates/convert/pdf-to-img.html +++ b/src/main/resources/templates/convert/pdf-to-img.html @@ -26,7 +26,6 @@ -