Skip to content

Commit

Permalink
Cater for dot in file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
dkayiwa committed Nov 5, 2024
1 parent d8ba8d5 commit 1409306
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
Expand Down Expand Up @@ -162,7 +163,11 @@ public Object upload(MultipartFile file, RequestContext context) throws Response
String fileType = tika.detect(file.getInputStream());
try {
MimeType mimeType = MimeTypes.getDefaultMimeTypes().forName(fileType);
if (!CollectionUtils.containsAny(mimeType.getExtensions(), Arrays.asList(allowedExtensions))) {

List<String> mimeTypeExtensions = mimeType.getExtensions().stream()
.map(extension -> extension.replace(".", "")).collect(Collectors.toList());

if (!CollectionUtils.containsAny(mimeTypeExtensions, Arrays.asList(allowedExtensions))) {
throw new IllegalRequestException("The file content type " + fileType + " is not allowed");
}
}
Expand Down

0 comments on commit 1409306

Please sign in to comment.