I have to upload the 100MB file. My front end part is Angular 4 and backend part is in Java and Spring 4 . I have exposed it as REST endpoint. Once i upload the file after sometime the connection get break and it does not return anything to the front end.
@SuppressWarnings("unchecked")
@RequestMapping(value = "/insertDoc.action", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> insertDoc(final HttpServletRequest request,
final HttpServletResponse response, @RequestParam(name = "docType", required = false) final String docType) {
List<DocumentMetadataVO> docIdList = new ArrayList<DocumentMetadataVO>();
try {
boolean isMultipart = ServletFileUpload.isMultipartContent(new ServletRequestContext(request));
if (isMultipart) {
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setFileSizeMax(MAX_FILE_SIZE);
upload.setSizeMax(MAX_REQUEST_SIZE);
List<FileItem> items = upload.parseRequest(request);
for (FileItem fileItem : items) {
DocumentMetadataVO documentMetadataVO = new DocumentMetadataVO();
documentMetadataVO.setFileData(fileItem.get());
documentMetadataVO.setDocumentName(fileItem.getName());
documentMetadataVO.setUploadDate(new Date());
logger.info("File Name is::" + documentMetadataVO.getDocumentName());
documentMetadataVO.setDocType(docType);
String docId = commonService.insertDocument(request, documentMetadataVO);
documentMetadataVO.setDocId(docId);
docIdList.add(documentMetadataVO);
}
}
} catch (Exception e) {
logger.error(e);
return new ResponseEntity<Map<String, Object>>(getModelMapError(e.getMessage()),
HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<Map<String, Object>>(getMap(docIdList), HttpStatus.OK);
}