Issue
Using spring MVC I receive multipart files in the controller this way
@RestController
public class FilesController {
@PostMapping(path = ("/files"), consumes = {"multipart/form-data", "multipart/mixed"})
public Reference createFile(
@RequestPart(value = "description") FileDescription fileDesc,
@RequestPart(value = "attachments", required = false) List<MultipartFile> attachments) {
Some parts of the multipart request may contain headers like "Content-ID", "Content-Location" and so on. But spring interface MultipartFile doesn't provide a method to get any header I want, only getContentType as I see. How I can get all provided headers?
Important point is that in request I could have multipart/mixed as a part of multipart/form-data. So every part of the message has its own map of headers. If I use @RequestHeader, I can see main headers of the request, but there are no headers of a specific part of multipart.
Solution
We can also use javax.servlet.http.Part instead of MultipartFile. Interface Part has getHeader method.
@RequestPart(value = "attachments", required = false) List<Part> attachments
Answered By - Ilya