Skip to content

Commit

Permalink
[CCAP-639] Handle Tika returning a special mime type for older versio…
Browse files Browse the repository at this point in the history
…ns of Office products (#644)

* [CCAP-639] Handle Tika returning a special mime type for older versions of Office products

* [CCAP-639] Handle Tika returning a special mime type for older versions of Office products
  • Loading branch information
cram-cfa authored Jan 28, 2025
1 parent 74288b9 commit 20d8577
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/formflow/library/file/FileValidationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.stereotype.Service;
import org.springframework.util.MimeType;
import org.springframework.web.multipart.MultipartFile;
import java.util.stream.Collectors;

/**
* This service is intended to help with miscellaneous file things. This service will help with checking mime types, both proper
Expand Down Expand Up @@ -75,11 +76,21 @@ public FileValidationService(
.sorted()
.toList();

ACCEPTED_MIME_TYPES = ACCEPTED_FILE_EXTS.stream()
List<MimeType> acceptedMimeTypes = ACCEPTED_FILE_EXTS.stream()
.filter(FILE_EXT_MIME_TYPE_MAP::containsKey)
.map(FILE_EXT_MIME_TYPE_MAP::get)
.sorted()
.toList();
.collect(Collectors.toList());

if (ACCEPTED_FILE_EXTS.contains(".doc")) {
// It's possible that Tika will return this for an MS Office document instead of the
// correct Mime Type, if the version of Office is old or Tika can't quite determine if
// it's a Word vs Excel document (for example)
// This little workaround will insert Tika's returned value in those cases of ambiguity.
acceptedMimeTypes.add(new MimeType("application", "x-tika-msoffice"));
}

ACCEPTED_MIME_TYPES = acceptedMimeTypes;

log.info(String.format("User provided file types: %s", userProvidedFileTypes));
log.info(String.format("Files accepted by the server: %s", String.join(JOIN_DELIMITER, ACCEPTED_FILE_EXTS)));
Expand Down

0 comments on commit 20d8577

Please sign in to comment.