@RequestMapping(value = "/savD", method = RequestMethod.POST) public ResponseEntity<Void> saveFile(@RequestParam("file") MultipartFile file) { if (!file.isEmpty()) { try { byte[] bytes = file.getBytes(); Document document = new Document(); document.setName(file.getOriginalFilename()); document.setContent(bytes); documentService.save(document); } catch (Exception e) { } } else { } HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
@RequestMapping(value = "/upload", method = RequestMethod.POST) public ResponseEntity uploadFile(MultipartHttpServletRequest request) { try { Iterator<String> itr = request.getFileNames(); while (itr.hasNext()) { String uploadedFile = itr.next(); MultipartFile file = request.getFile(uploadedFile); String mimeType = file.getContentType(); String filename = file.getOriginalFilename(); byte[] bytes = file.getBytes(); Document document = new Document(); document.setContent(bytes); document.setName(filename); document.setMimeType(mimeType); documentService.save(document); } } catch (Exception e) { return new ResponseEntity<>("{}", HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity<>("{}", HttpStatus.OK); }