For example:
Creating the body
import io.micronaut.http.multipart.CompletedFileUpload
import io.micronaut.http.multipart.StreamingFileUpload
import io.micronaut.http.client.multipart.MultipartBody
import org.reactivestreams.Publisher
File file = new File(uploadDir, "data.txt")
file.createNewFile()
MultipartBody requestBody = MultipartBody.builder() (1)
.addPart( (2)
"data",
MediaType.TEXT_PLAIN_TYPE,
file
).build() (3)
Creating a request
HttpRequest.POST("/multipart/upload", requestBody) (1)
.contentType(MediaType.MULTIPART_FORM_DATA_TYPE) (2)
Creating a request
HttpRequest.POST("/multipart/upload", requestBody) (1)
1 | The multipart request body with different sets of data. |
2 | Set the content-type header of the request to multipart/form-data . |