Multipart uploads
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
accept a file in a request.
Planned topics
- Browsers and clients upload files with
multipart/form-data: the body has several named parts, each with its own headers. - In Spring, bind a file part with
@RequestPartor@RequestParamof typeMultipartFile. MultipartFilegives the original name, content type, size, and a stream of bytes.- Other form fields can arrive in the same request.
- Test with
curl -F "file=@pen.png".
Draft outline details
Demonstration
@PostMapping(value = "/products/{id}/images", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
ResponseEntity<ImageResponse> upload(@PathVariable long id, @RequestParam("file") MultipartFile file) { ... }Check your understanding
Which content type carries file uploads?
Show answer
multipart/form-data.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.