Skip to content

Commit

Permalink
use contentType from Document metadata when uploading a Document with…
Browse files Browse the repository at this point in the history
… REST (#4121)
  • Loading branch information
McAlm authored Feb 24, 2025
1 parent d40ff5b commit 1e0501a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,16 @@ private HttpEntity createMultiPartEntity(Map<?, ?> body, ContentType contentType
private void streamDocumentContent(
Map.Entry<?, ?> entry, Document document, MultipartEntityBuilder builder) {
DocumentMetadata metadata = document.metadata();
ContentType contentType;
try {
contentType = ContentType.create(metadata.getContentType());
} catch(IllegalArgumentException e){
contentType = ContentType.DEFAULT_BINARY;
}
builder.addBinaryBody(
String.valueOf(entry.getKey()),
new BufferedInputStream(document.asInputStream()),
ContentType.DEFAULT_BINARY,
contentType,
metadata.getFileName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void shouldReturn201_whenUploadDocument(WireMockRuntimeInfo wmRuntimeInfo
store.createDocument(
DocumentCreationRequest.from("The content of this file".getBytes())
.fileName("file.txt")
.contentType("text/plain")
.build());
HttpCommonRequest request = new HttpCommonRequest();
request.setMethod(HttpMethod.POST);
Expand Down Expand Up @@ -153,6 +154,7 @@ public void shouldReturn201_whenUploadDocument(WireMockRuntimeInfo wmRuntimeInfo
new MultipartValuePatternBuilder()
.withName("document")
.withBody(equalTo("The content of this file"))
.withHeader("Content-Type", equalTo("text/plain"))
.build()));
}
}
Expand Down

0 comments on commit 1e0501a

Please sign in to comment.