Skip to content

Instantly share code, notes, and snippets.

@jcyuyi
Created March 28, 2019 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcyuyi/0a672dd1b2527dceb22442b5ae6f4a72 to your computer and use it in GitHub Desktop.
Save jcyuyi/0a672dd1b2527dceb22442b5ae6f4a72 to your computer and use it in GitHub Desktop.
SpringBoot Web Snippet

Multipart form files uploading

Server side

@PostMapping("/uploads", consumes = ["multipart/form-data"])
fun sendApplyEmail(
    @RequestPart body: FormBodyDto, 
    @RequestPart("files", required = false) files: List<MultipartFile>
) {
    // handle body and files...
}

Client side

let formData = new FormData();
for (let i = 0; i < this.files.length; i++) {
  formData.append("files", this.files[i]);
}
let jsonBlob = new Blob([JSON.stringify(this.form)], {
  type: "application/json"
})
formData.append("body", jsonBlob);