Looking for help to read file content from multipart response?

515 views
Skip to first unread message

Sajan Soosaimicheal

unread,
Aug 8, 2021, 8:04:12 PM8/8/21
to Quarkus Development mailing list
Hello All,

looking for help to get file content from multipart file upload "requestBody".  not sure how to read from "requestBody". please share if have any example.

@POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.TEXT_PLAIN) public String echo(String requestBody) throws Exception { return requestBody; }


KimJohn Quinn

unread,
Aug 9, 2021, 7:31:47 AM8/9/21
to Quarkus Development mailing list
This worked for us (single-file)...

File Upload (Multipart Form):

@Schema(description = "Single file upload")
public class FileUpload {

    @FormParam("file")
    @PartType(APPLICATION_OCTET_STREAM)
    public File data;

    @FormParam("filename")
    @PartType(TEXT_PLAIN)
    public String fileName;

    @FormParam("path")
    @PartType(TEXT_PLAIN)
    public String path;

    @FormParam("mimetype")
    @PartType(TEXT_PLAIN)
    public String mimeType;
}

File Upload (REST resource):

/**
 * Upload a file
 */
@POST
@Path("/upload")
@Consumes(MULTIPART_FORM_DATA)
@RequestBody(
    content = @Content(
        mediaType = MULTIPART_FORM_DATA,
        schema = @Schema(implementation = FileUpload.class)))
@Operation(summary = "Upload file")
public Uni<Response> upload(@MultipartForm final FileUpload request, final @BeanParam ProjectParams params) throws Exception {
}

Resource Test:

given().pathParam("client", "my-client")
        .pathParam("project", "my-project")
        .multiPart("file", readFile().toFile())
        .multiPart("path", "a/b")
        .multiPart("filename", "sample1.txt")
        .multiPart("mimetype", "text/plain")
        .when()
        .post("/s3/storage/{client}/{project}")
        .then()
        .statusCode(CREATED.getStatusCode());

Maven Dependencies:

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-rest-client-reactive-jackson</artifactId>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>

Sajan Soosaimicheal

unread,
Aug 22, 2021, 5:44:07 PM8/22/21
to Quarkus Development mailing list
thanks @KimJohn. we are creating Rest API using quarks and it's not reactive. 

Sajan Soosaimicheal

unread,
Aug 22, 2021, 5:51:16 PM8/22/21
to Quarkus Development mailing list
error message:
2021-08-22 17:50:13,096 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /api/788/networktraffic failed, error id: 0f131f19-8a83-4310-8eca-f59703aa1151-1: java.lang.NoClassDefFoundError: org/jboss/resteasy/spi/config/ConfigurationFactory
Reply all
Reply to author
Forward
0 new messages