feat(signature): add SVG file support for saved signatures (#4742)

This update adds full support for SVG signature files within the **Sign
module**.
Previously, SVG images could be uploaded and used directly but did not
appear under the “Saved Signatures” section.

### What was changed
- **`SignatureService`**:  
Extended `isImageFile()` method to include `.svg` file extension,
ensuring SVGs are recognized as valid image files.
- **`SignatureController`**:  
Enhanced response handling using `MediaTypeFactory` to dynamically
determine and return the correct `MediaType` based on the file name.
This allows serving `image/svg+xml` for SVG files instead of the
previous hardcoded `image/jpeg`.

### Why the change was made
SVG signature files were not appearing in “Saved Signatures” even though
they could be uploaded and used manually.
This fix ensures consistent handling and display of SVG images alongside
other image types (JPG, PNG, GIF).

Closes #4731

---

## Checklist

### General

- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [x] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.
This commit is contained in:
Ludy 2025-10-30 11:09:52 +01:00 committed by GitHub
parent e715f14c0a
commit 0f7ea1aed1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 5 deletions

View File

@ -1,10 +1,12 @@
package stirling.software.SPDF.controller.web;
import java.io.IOException;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.MediaTypeFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@ -41,9 +43,14 @@ public class SignatureController {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
byte[] imageBytes = signatureService.getSignatureBytes(username, fileName);
Optional<MediaType> mediaType = MediaTypeFactory.getMediaType(fileName);
if (mediaType.isPresent() && mediaType.get().toString().startsWith("image/")) {
return ResponseEntity.ok()
.contentType( // Adjust based on file type
MediaType.IMAGE_JPEG)
mediaType.get())
.body(imageBytes);
}
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
}

View File

@ -96,7 +96,8 @@ public class SignatureService {
return fileName.endsWith(".jpg")
|| fileName.endsWith(".jpeg")
|| fileName.endsWith(".png")
|| fileName.endsWith(".gif");
|| fileName.endsWith(".gif")
|| fileName.endsWith(".svg");
}
private void validateFileName(String fileName) {