8 Oct 2017

HTTP content type headers for different purpose in Rest API

Rest API  to return a zip file as download

@RequestMapping(value="/v1/collection_service/response/{appReferenceId}", method=RequestMethod.GET, produces=MediaType.MULTIPART_FORM_DATA_VALUE)

 public ResponseEntity<?> collectionServiceProfile(@PathVariable(value="appReferenceId") String appReferenceId){
  ByteBuffer byteBuffer = collectionService.getCollectionProfileZip(appReferenceId);
  MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
  headers.add(HttpHeaders.CONTENT_TYPE, "application/zip");
  return new ResponseEntity<>(byteBuffer.array(), headers, HttpStatus.OK);
 }

The line in the block is the one that determines that the content should be downloaded as zip.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.