Environment:
Spring Boot / Spring Boot Starter Batch Version 1.5.6.RELEASE
Oracle Java 8
1. multipart/form-data POST request with request parameter metadata
curl:
curl -k -H 'Content-Type: multipart/form-data' -F 'docFiles=@test1.txt;type=text/plain' 'https://localhost:8443/cherryshoe-app/document/file/upload/REVIEW?id=3554&docTypeId=1'
-k is to to turn off curl's verification of the self-signed certificate
-F Contents to be read from file use the @
Matching Java Controller Method Signature:
@RequestMapping(value = "/document/
file/upload", consumes = "multipart/form-data", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
@ResponseBody
public DocumentUploadMetadata fileUpload(
@RequestParam(value = "id", required = true) final Long reviewId,
@RequestParam(value = "docTypeId", required = true) final Long docTypeId,
@RequestParam("docFiles") List<MultipartFile> docFiles, Principal principal)
throws IllegalArgumentException, NullPointerException, Exception {
}
2. multipart/form-data POST request with JSON request body metadata
curl:
curl -k -H 'Content-Type: multipart/form-data' -F 'docFiles=@test1.txt;type=text/plain' -F metadata='{"reviewId":3554,"docTypeId":1,"customFileName":"customFileName.txt","commentText":"This is a really long text, it may even be in HTML"};type=application/json' 'https://localhost:8443/cherryshoe-app/document/file/upload'
-k is to to turn off curl's verification of the self-signed certificate
-F Contents to be read from file use the @
Matching Java Controller Method Signature:
@RequestMapping(value = "/document/file/upload", consumes = "multipart/form-data", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
@ResponseBody
public DocumentUploadMetadata fileUpload(@RequestPart("docFiles") List<MultipartFile> docFiles,
@RequestPart("metadata") DocumentUploadMetadata metadata, Principal principal)
throws IllegalArgumentException, NullPointerException, Exception {
}
This Signature also works, had to do this to work with ng-file-upload library:
/**
* Takes a list of document MultipartFile's, and JSON metadata.
*
* NOTE: To make this work with ng-file-upload: - have to pass the JSON
* metadata as a String, and then deserialize the JSON String manually in
* the controller.
*
* @param docFiles
* @param metadata
* @param principal
* @return
* @throws IllegalArgumentException
* @throws NullPointerException
* @throws Exception
*/
@RequestMapping(value = "/document/file/upload", consumes = "multipart/form-data", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
@ResponseBody
public DocumentUploadMetadata fileUpload(@RequestParam("docFiles") List<MultipartFile> docFiles,
@RequestParam("metadata") String metadataJson, Principal principal)
throws IllegalArgumentException, NullPointerException, Exception {
// deserialize metadataJson JSON string manually
}
POJO for JSON metadata serialization/deserialization:
public class DocumentUploadMetadata {
private Long reviewId;
private Long docTypeId;
private String customFileName;
private String commentText;
public DocumentUploadMetadata() {
super();
}
// getters and setters are needed for jackson serialization/deserialization, add them for this to work
}
Helpful curl documentation: https://curl.haxx.se/docs/manual.html
I am feeling great to read this.you gave a nice info for us.please update more.
ReplyDeletePython Training in Chennai
Python Training Institute in Chennai
JAVA Training in Chennai
Hadoop Training in Chennai
Selenium Training in Chennai
Python Training in Chennai
Python Training in Tambaram
IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes. IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble.Final Year Projects for CSE
DeleteSpring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining .
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai
The Angular Training covers a wide range of topics including Angular Directives, Angular Services, and Angular programmability.Angular Training
I have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective. Techno-based information has been fetched in each of your topics. Sure it will enhance and fill the queries of the public needs. Feeling so glad about your article. Thanks…!
ReplyDeletebest software testing training in chennai
best software testing training institute in chennai with placement
software testing training
courses
software testing training and placement
software testing training online
software testing class
software testing classes in chennai
best software testing courses in chennai
automation testing courses in chennai
digital marketing training in chennai
digital marketing classes in chennai
digital marketing course in chennai
digital marketing institute in chennai
digital marketing training centers in chennai
digital marketing training institute in chennai
best digital marketing course in chennai
Thanks for sharing this valuable information to our vision. You have posted a worthy blog keep sharing.
ReplyDeleteDigital Marketing Course In Kolkata
Web Design Course In Kolkata
SEO Course In Kolkata
I like the blog format as you create user engagement in the complete article. Thanks for the informative posts.
ReplyDeleteBig Data Hadoop Training In Chennai | Big Data Hadoop Training In anna nagar | Big Data Hadoop Training In omr | Big Data Hadoop Training In porur | Big Data Hadoop Training In tambaram | Big Data Hadoop Training In velachery
I was following your blog regularly and this one is very interesting and knowledge attaining. Great effort ahead. you can also reach us for website development in chennai website design company in chennai
ReplyDeletenike lebron 15
ReplyDeletemoncler
golden goose outlet
balenciaga
yeezy shoes
yeezy shoes
supreme hoodie
supreme outlet
yeezy shoes
golden goose sneakers
yeezy 700
ReplyDeletelebron 18
yeezy shoes
lebron james shoes
pandora
off white shoes
giannis shoes
supreme
lebron 17 shoes
pandora
The Article is good, really helpful and knowledge attaining
ReplyDeleteSofa Cleaning Services in Chennai
Sofa Renovation in Chennai
Sofa Repair in Chennai
Sofa Upholstery in Chennai
Car Seat Upholstery in Chennai