Encoding file to base64

@RequestParam("file") MultipartFile file

...

if (!file.isEmpty()) {
			String base64 = Base64.getEncoder().encodeToString(file.getBytes());
}

Decoding base64 to file

HttpServletResponse response

...

response.addHeader("Content-disposition", "inline");
response.setContentType("audio/mpeg");
  		 
Attachment attachment = attachmentRepository.findOne(id);
byte[] decodedBytes = Base64.getDecoder().decode(attachment.getBase64());
  		
OutputStream output = response.getOutputStream();
output.write(decodedBytes);
output.close();