Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUpload is null when uploading file with Resteasy Reactive #23079

Closed
zakhdar opened this issue Jan 21, 2022 · 5 comments
Closed

FileUpload is null when uploading file with Resteasy Reactive #23079

zakhdar opened this issue Jan 21, 2022 · 5 comments
Labels
area/rest kind/bug Something isn't working triage/duplicate This issue or pull request already exists

Comments

@zakhdar
Copy link

zakhdar commented Jan 21, 2022

Describe the bug

I have a Resteasy client (JSF app running on WildFly) from wich i upload file to quarkus resteasy classic app and it's work well.
When i use the same client with a resteasy reactive app the 'FileUpload' part of the multipart-form is always null.

Pojo enclosing Multipart body on my client side (JSF app)

@JsonIgnoreProperties(ignoreUnknown = true)
public class MultipartBody implements Serializable {

    @FormParam("document")
    @PartType(MediaType.APPLICATION_OCTET_STREAM)
    public InputStream document;

    @FormParam("fileName")
    @PartType(MediaType.TEXT_PLAIN)
    public String fileName;

    @FormParam("contentType")
    @PartType(MediaType.TEXT_PLAIN)
    public String contentType;

    @FormParam("size")
    @PartType(MediaType.TEXT_PLAIN)
    public Long size;

    @FormParam("entityType")
    @PartType(MediaType.TEXT_PLAIN)
    public String entityType;

    @FormParam("entityId")
    @PartType(MediaType.TEXT_PLAIN)
    public String entityId;
    ...

Endpoint on quarkus resteasy classic

@Path("/v1/datastore")
public class ExampleResource {

    @POST
    @Path("/upload")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(@MultipartForm MultipartBody data) {
        System.out.println("[MultiPart] "+data);
        return Response.ok().build();
    }
}

the MultipartBody pojo is the same im using on my client side

Console output when uploading file



2022-01-21 02:14:19,846 INFO  [io.quarkus] (Quarkus Main Thread) multipart 1.0-SNAPSHOT on JVM (powered by Quarkus 2.6.3.Final) started in 1.871s. Listening on: http://localhost:9092
2022-01-21 02:14:19,849 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2022-01-21 02:14:19,849 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy, resteasy-jackson, resteasy-multipart, smallrye-context-propagation, vertx]
[MultiPart] MultipartBody(document=C:\Users\ZOULAK~1\AppData\Local\Temp\pfx14102355135171294723sfx, fileName=avatar.png, contentType=image/png, size=268398, entityType=orga-attachment, entityId=ent1)

All parts of the multipart-form are present.

Endpoint on quarkus resteasy reactive
it's the same as the classic one but changing all dependencies in pom to resteasy reactive

@Path("/v1/datastore")
public class ExampleResource {
    @POST
    @Path("/upload")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(@MultipartForm MultipartBody data) {
        System.out.println("[MultiPart] "+data);
        return Response.ok().build();
    }
}

MultipartBody pojo on quarkus resteasy reactive

@JsonIgnoreProperties(ignoreUnknown = true)
public class MultipartBody {

    @RestForm
    @PartType(MediaType.APPLICATION_OCTET_STREAM)
    public FileUpload document;

    @RestForm
    @PartType(MediaType.TEXT_PLAIN)
    public String fileName;

    @RestForm
    @PartType(MediaType.TEXT_PLAIN)
    public String contentType;

    @RestForm
    @PartType(MediaType.TEXT_PLAIN)
    public Long size;

    @RestForm
    @PartType(MediaType.TEXT_PLAIN)
    public String entityType;

    @RestForm
    @PartType(MediaType.TEXT_PLAIN)
    public String entityId;
    ...

Console output when uploading file

2022-01-21 02:23:07,483 INFO  [io.quarkus] (Quarkus Main Thread) multipart-reactive 1.0-SNAPSHOT on JVM (powered by Quarkus 2.6.3.Final) started in 1.774s. Listening on: http://localhost:9092
2022-01-21 02:23:07,495 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2022-01-21 02:23:07,495 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy-reactive, resteasy-reactive-jackson, smallrye-context-propagation, vertx]
[MultiPart] MultipartBody(document=null, fileName=avatar.png, contentType=image/png, size=268398, entityType=orga-attachment, entityId=ent1)

The 'document' part corresponding to FileUpload property of MultipartBody is always null , the others properties are correctly set.

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

11

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.6.3

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@zakhdar zakhdar added the kind/bug Something isn't working label Jan 21, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 21, 2022

/cc @FroMage, @geoand, @stuartwdouglas

@zakhdar
Copy link
Author

zakhdar commented Jan 21, 2022

don't know if it can help but i write a small request filter to print out the entity body of request and the 'document' part is not null in the filter (i have truncated it in the console output bellow)

 @ServerRequestFilter
    public Optional<Response> getFilter(ContainerRequestContext ctx) {
        InputStream is = ctx.getEntityStream();
        try {
            byte[] data = is.readAllBytes();
            String body = new String(data, StandardCharsets.UTF_8);
            System.out.println(body);
            ctx.setEntityStream(new ByteArrayInputStream(data));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Optional.empty();
    }

Filter output

2022-01-21 03:18:44,693 INFO  [io.quarkus] (Quarkus Main Thread) multipart-reactive 1.0-SNAPSHOT on JVM (powered by Quarkus 2.6.3.Final) started in 1.705s. Listening on: http://localhost:9092
2022-01-21 03:18:44,705 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2022-01-21 03:18:44,705 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy-reactive, resteasy-reactive-jackson, smallrye-context-propagation, vertx]
--23d8557b-43bd-4358-b960-a32f182e561d
Content-Disposition: form-data; name="fileName"
Content-Type: text/plain

avatar.png
--23d8557b-43bd-4358-b960-a32f182e561d
Content-Disposition: form-data; name="size"
Content-Type: text/plain

268398
--23d8557b-43bd-4358-b960-a32f182e561d
Content-Disposition: form-data; name="entityType"
Content-Type: text/plain

orga-attachment
--23d8557b-43bd-4358-b960-a32f182e561d
Content-Disposition: form-data; name="document"
Content-Type: application/octet-stream

?PNG
�
IHDR  �   ��   ?$�   	pHYs  ��  ��� ??�    IDATx???{?\?}?q?eY?%Y??�??0??M??Q?v????D?"?G*???3�X.�"r��M�?f?60�?.?@Y'A??V ??{?�?sv?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           }]�            ?N??so3?/I?$?;z? ??Y?u??�            ?1???�?????.??]?.?o�>X$I?$i;???a?t[@?-$?t???C_?            ?????v???;v?
...
... 
...
�??-04$I?$i??B~?^g??�cm???????????��           ?A???-??�l?
??�??M??C????%?�??�m?u�Ws??gG??*?.???�??Q\?vc~??e??B::��q???2ffc'>8�K??2?????1�o(c?�?!}???2F?X-c??y�              p?�???�?5?r(??K
???+_??�???K??�O????|??????o|??^?{R????=*?j?m??rO?-???q�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ???�n??A?yt?    IEND?B`?
--23d8557b-43bd-4358-b960-a32f182e561d
Content-Disposition: form-data; name="entityId"
Content-Type: text/plain

ent1
--23d8557b-43bd-4358-b960-a32f182e561d
Content-Disposition: form-data; name="contentType"
Content-Type: text/plain

image/png
--23d8557b-43bd-4358-b960-a32f182e561d--
[MultiPart] MultipartBody(document=null, fileName=avatar.png, contentType=image/png, size=268398, entityType=orga-attachment, entityId=ent1)

@geoand
Copy link
Contributor

geoand commented Jan 21, 2022

The FileUpload part is null because there is no filename attribute in the chunk that defines the file. This is essentially the same issue as #20938.

@stuartwdouglas should we update the parser to handle this use case? I personally think what RESTEasy Reactive does currently is correct FWIW...

@zakhdar
Copy link
Author

zakhdar commented Jan 21, 2022

Hi @geoand ,
thank you for your response , after added @PartFilename("filename") on the field on client side it's work as expected

@geoand
Copy link
Contributor

geoand commented Jan 21, 2022

Great to hear!

I will close this issue as a duplicate of #20938.

@geoand geoand closed this as completed Jan 21, 2022
@geoand geoand added the triage/duplicate This issue or pull request already exists label Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest kind/bug Something isn't working triage/duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants