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

RESTEasy Reactive - Support text/binary conversion for multipart files #27498

Merged
merged 1 commit into from Aug 26, 2022

Conversation

Sgitario
Copy link
Contributor

@Sgitario Sgitario commented Aug 25, 2022

Assuming we receive the following request:

Content-Disposition: form-data; name="textPart"; filename="my_file.txt"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

We can load the content of the file using the FileUpload class:

public class FormData {
    @FormParam("myFile")
    public FileUpload myFile;
}

However, according to what the specs state:

The presence of the filename parameter does not force an
implementation to write the entity to a separate file. It is
perfectly acceptable for implementations to leave the entity as part
of the normal mail stream unless the user requests otherwise. As a
consequence, the parameter may be used on any MIME entity, even
`inline' ones. These will not normally be written to files, but the
parameter could be used to provide a filename if the receiving user
should choose to write the part to a file.

Then, we should not enforce the use of FileUpload and hence also support reading the whole content of the file into strings, and other binary formats like byte[] and InputStream.

public class FormData {
    @FormParam("myFile")
    @PartType(MediaType.APPLICATION_OCTET_STREAM)
    public String myFile;
}

public class FormData {
    @FormParam("myFile")
    @PartType(MediaType.APPLICATION_OCTET_STREAM)
    public byte[] binaryPart;
}

public class FormData {
    @FormParam("myFile")
    @PartType(MediaType.APPLICATION_OCTET_STREAM)
    public InputStream streamPart;
}

Fix #27083

@quarkus-bot

This comment has been minimized.

Assuming we receive the following request:
```
Content-Disposition: form-data; name="textPart"; filename="my_file.txt"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
```

We can load the content of the file using the `FileUpload` class:

```java
public class FormData {
    @FormParam("myFile")
    public FileUpload myFile;
}
```

However, according to what the specs state:
```
The presence of the filename parameter does not force an
implementation to write the entity to a separate file. It is
perfectly acceptable for implementations to leave the entity as part
of the normal mail stream unless the user requests otherwise. As a
consequence, the parameter may be used on any MIME entity, even
`inline' ones. These will not normally be written to files, but the
parameter could be used to provide a filename if the receiving user
should choose to write the part to a file.
```

Then, we should not enforce the use of `FileUpload` and hence also support reading the whole content of the file into strings, and other binary formats like byte[] and InputStream.

```java
public class FormData {
    @FormParam("myFile")
    @PartType(MediaType.APPLICATION_OCTET_STREAM)
    public String myFile;
}

public class FormData {
    @FormParam("myFile")
    @PartType(MediaType.APPLICATION_OCTET_STREAM)
    public byte[] binaryPart;
}

public class FormData {
    @FormParam("myFile")
    @PartType(MediaType.APPLICATION_OCTET_STREAM)
    public InputStream streamPart;
}
```

Fix quarkusio#27083
@geoand geoand added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Aug 26, 2022
@geoand geoand merged commit d69cd81 into quarkusio:main Aug 26, 2022
@quarkus-bot quarkus-bot bot added this to the 2.13 - main milestone Aug 26, 2022
@quarkus-bot quarkus-bot bot added kind/bugfix and removed triage/waiting-for-ci Ready to merge when CI successfully finishes labels Aug 26, 2022
FroMage added a commit to FroMage/quarkus that referenced this pull request Aug 26, 2022
@Sgitario Sgitario deleted the rr_multipart branch August 29, 2022 05:16
FroMage added a commit to FroMage/quarkus that referenced this pull request Oct 4, 2022
FroMage added a commit to FroMage/quarkus that referenced this pull request Oct 10, 2022
FroMage added a commit to FroMage/quarkus that referenced this pull request Oct 11, 2022
FroMage added a commit to FroMage/quarkus that referenced this pull request Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RESTEasy Reactive - Server side multipart implementation is not being respected
2 participants