Jax-RS Multipart response
By : Riz920
Date : March 29 2020, 07:55 AM
will help you In Jersey you can use jersey-media-multipart module to make your life easier. Follow the documentation on this topic: Multipart section in Jersey User Guide or take a look at the available example multipart-webapp.
|
Constructing multipart response
By : tdalseide
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Got it. You can also add complete response to a MultipartContent as well. code :
MultipartContent content = new MultipartContent("mixed", "----Boundary");
content.Add(new HttpMessageContext(response1));
content.Add(new HttpMessageContext(response2));
|
How to send a multipart file to a service from another service
By : DADATA
Date : March 29 2020, 07:55 AM
hope this fix your issue I have two endpoints api which are /uploadand /redirect , This made the trick code :
@RequestMapping(value = "/redirect", produces = { MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.POST)
public ResponseEntity<?> registerBatchUser(@RequestParam("file") MultipartFile file) {
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream = new BufferedOutputStream(
new FileOutputStream(new File("D:\\myfileredirect.csv")));
stream.write(bytes);
stream.close();
} catch (Exception e) {
JwtAuthenticationErrorResponse FeedBackResponse = new JwtAuthenticationErrorResponse();
FeedBackResponse.setCode(100);
FeedBackResponse.setMessage(e.getMessage());
Map<String, Object> FeedBackStatus = new HashMap<String, Object>();
FeedBackStatus.put("status", FeedBackResponse);
return ResponseEntity.ok(FeedBackStatus);
}
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
parameters.add("file", new FileSystemResource("D:\\myfileredirect.csv"));
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "multipart/form-data");
Map<String, Object> FeedBackStatus=new HashMap<String, Object>();
FeedBackStatus = restTemplateUserRegitration.exchange("http://localhost:8080/upload", HttpMethod.POST, new HttpEntity<MultiValueMap<String, Object>>(parameters, headers), Map.class).getBody();
return ResponseEntity.ok(FeedBackStatus);
}
|
How to parse and save a Multipart/related type=image/jpeg response? (Dicom Wado Response)
By : user3232723
Date : March 29 2020, 07:55 AM
|
How to pass Multipart file from one service to another service in spring boot?
By : YanYan22
Date : March 29 2020, 07:55 AM
help you fix your problem At last able to solve the communication issue to the another service using the post File upload spring cloud feign clientI have changed the FeignClient parameter type from code :
@PostMapping(value="/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
ResponseEntity<Properties> upload(@RequestHeader(name=UID,required=false) String uid, @RequestPart("file") MultiValueMap<String, Object> file);
@PostMapping(path="/upload")
public ResponseEntity<Properties> uploadAttachment(@RequestHeader(IRSConsts.UID) String uid, @RequestParam("file") MultipartFile mFile) {
MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
ByteArrayResource contentsAsResource = null;
try {
contentsAsResource = new ByteArrayResource(mFile.getBytes()) {
@Override
public String getFilename() {
return mFile.getOriginalFilename();
}
};
} catch (IOException e) {
e.printStackTrace();
}
multiValueMap.add("file", contentsAsResource);
return transSvcClient.upload(uid, multiValueMap);
}
@PostMapping(path = "/upload")
@Headers("Content-Type: multipart/form-data")
public ResponseEntity<Properties> upload(@RequestHeader(name = UID, required = false) String uid,
@RequestPart("file") MultipartFile multiPart) {
//Save Attachment.
}
|