Skip to content

Commit 1a247eb

Browse files
authored
Merge pull request #48778 from piu130/fix/multipart-string
Add support for reading in memory file to string in multipart
2 parents 6241ec3 + 578df3b commit 1a247eb

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

extensions/resteasy-reactive/rest/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/multipart/FormDataWithAllUploads.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class FormDataWithAllUploads extends FormDataBase {
1818
@PartType(MediaType.TEXT_PLAIN)
1919
private Status status;
2020

21+
@RestForm
22+
private String stringWithFilename;
23+
2124
@RestForm(FileUpload.ALL)
2225
private List<FileUpload> uploads;
2326

extensions/resteasy-reactive/rest/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/multipart/MultipartInputWithAllUploadsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public void testSimple() throws IOException {
6464
RestAssured.given()
6565
.multiPart("name", "Alice")
6666
.multiPart("active", "true")
67+
.multiPart("stringWithFilename", "a-string", "application/xfdf")
6768
.multiPart("num", "25")
6869
.multiPart("status", "WORKING")
6970
.multiPart("htmlFile", HTML_FILE, "text/html")
@@ -74,7 +75,7 @@ public void testSimple() throws IOException {
7475
.post("/multipart-all/simple/2")
7576
.then()
7677
.statusCode(200)
77-
.body(equalTo("Alice - true - 50 - WORKING - 3 - text/plain"));
78+
.body(equalTo("Alice - true - 50 - WORKING - 4 - text/plain"));
7879

7980
// ensure that the 3 uploaded files where created on disk
8081
Assertions.assertEquals(3, uploadDir.toFile().listFiles().length);

independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/multipart/MultipartSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public static String getString(String formName, ResteasyReactiveRequestContext c
201201
// this is only for the TCK and regular form params
202202
if (value.isFileItem()) {
203203
try {
204-
return Files.readString(value.getFileItem().getFile(), Charset.defaultCharset());
204+
return new String(value.getFileItem().getInputStream().readAllBytes());
205205
} catch (IOException e) {
206206
throw new MultipartPartReadingException(e);
207207
}

0 commit comments

Comments
 (0)