I want to upload my image together with some boolean flag in my post request. I want these two values to be in the body so I used multipart/form-data
content type, and want to do something following:
void uploadNewImage(
@RequestPart Boolean flag,
@RequestPart("file") @NotBlank MultipartFile file) throws IOException {
....;
}
but when I use swagger, I get an exception: "message": "Content type 'application/octet-stream' not supported"
I googled for some advice and all of them to change @RequestPart
-> @RequestParam
. It works indeed, but in the request that is sent by swagger, I see flag
passed as the query param, but not in the body.
So I'm wondering how can I pass flag
in the body
Update 1:
If my flag
is in the body anyway since it's POST, why people use multipart/form-data
in such cases, when they want to upload an image, and transfer a simple java type (String/Long)
Can I proceed with a simple code like the above? Does it mean the same?
void uploadNewImage(
@RequestParam Boolean flag,
@RequestBody byte[] image) {
....
}
Of cause omit that in one case I use MultipartFile
and in another - byte[]
, but rather than this - there is no difference, and flag
will be passed in a query(again, is it gonna be in the body here as well?)