-
Notifications
You must be signed in to change notification settings - Fork 3k
Add support for reading in memory file to string in multipart #48778
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
Conversation
Thanks for your pull request! Your pull request does not follow our editorial rules. Could you have a look?
This message is automatically generated by a bot. |
Current workaround is to use ByteArray instead of String, because the |
Thanks for the contribution! Can you please show an example where this change is needed vs what the current code does? Also, having tests that handle this case is also necessary. |
Hi @geoand, thanks for checking. I've created a DTO: class FileUploadBody{
@RestForm("file")
lateinit var file: FileUpload
@RestForm("annotations")
@PartType("application/xfdf")
lateinit var annotations: String
} and a test: Given {
contentType(MediaType.MULTIPART_FORM_DATA)
multiPart(
"file",
File("src/test/resources/files/Test.pdf"),
CustomMediaType.APPLICATION_PDF,
)
multiPart(
"annotations",
"bla.xfdf",
"my-annots",
"application/xfdf",
)
} When {
post("upload")
} Then {
statusCode(Response.Status.CREATED.statusCode)
} This code throws a NullPointer at the line I've fixed in this MR. I don't know what to test. I did not change any logic and the current tests still works. A unit test for this fix does not make sense, since my unit is not interested in isInMemory. Neither would a service test (the code above), since the next commit could change the behavior of isInMemory and the code would be skipped. Please give me some directions for what to test and where to put these test(s) if necessary. Also note the comment of
|
We would need a test(or tests) like the ones we have here |
@geoand Thanks for the link :) I've adjusted a test throwing a NullPointer without the fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Status for workflow
|
When
FileItem.isInMemory
istrue
,value.getFileItem().getFile()
throws a NullPointerException. This MR fixes the problem by using the independentFileItem.getInputStream
-Method which works for in memory and not in memory FileItems.