title: How to upload download files to amazon s3 bucket with my current code
body: <p>I have this spring boot application that uses conventional way of document upload and download (By creating a folder on server), it takes files from html as multipart and we also have our android application web services which sends the data to rest controllers as base64 then converts it into byte format.
  Please tell me how can I implement the same code to s3 bucket with minimal changes.</p>
  
  <p>Service implementation class </p>
  
  <pre><code>package com.erp.serviceimpl;
  
  import java.io.IOException;
  import java.nio.file.Files;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.util.Collection;
  import java.util.Date;
  import java.util.List;
  
  import org.apache.commons.codec.binary.Base64;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.web.multipart.MultipartFile;
  
  import com.erp.model.Document;
  import com.erp.repository.DocumentRepository;
  import com.erp.service.DocumentService;
  
  @Service
  public class DocumentServiceImpl implements DocumentService {
  
      @Autowired
      DocumentRepository documentrepository;
  
      // Save the uploaded file to this folder
      private static String UPLOADED_FOLDER = "s3://elasticbeanstalk-ap-south-1-461760552509/imagesUpload/";
  
      @Override
      public boolean uploadUserImage(MultipartFile file, Document document) {
          System.out.println("pooja" + file);
          boolean status = false;
          if (document != null) {
              document.setDate(new Date());
              document.setTurbine_id(document.getTurbine_id());
              Document documentImage = documentrepository.save(document);
              if (documentImage != null) {
  
                  try {
                      byte[] bytes = file.getBytes();
                      Path path = Paths.get(UPLOADED_FOLDER + document.getDocId() + "_" + file.getOriginalFilename());
                      Files.write(path, bytes);
  
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
  
                  documentImage.setUploadImagesPath(document.getDocId() + "_" + file.getOriginalFilename());
                  documentrepository.save(documentImage);
                  return true;
              } else {
                  return false;
              }
          }
          return status;
      }
  
  
      @Override
      public List&lt;Document&gt; getAllImages() {
          return documentrepository.findAll();
      }
  
      @Override
      public List&lt;Document&gt; findAllByTurbine_id(int turbine_id) {
          // TODO Auto-generated method stub
          Iterable&lt;Document&gt; itr = documentrepository.findAllByTurbine_id(turbine_id);
          return (List&lt;Document&gt;)itr;
      }
  
      @Override
      public boolean uploadUserWebServiceImage(Document document) {
          boolean status = false;
          if (document != null) {
              document.setDate(new Date());
              document.setTurbine_id(document.getTurbine_id());
              Document documentImage = documentrepository.save(document);
              if (documentImage != null) {
                  try {
                      String[] img = document.getImageBase().split(",");
                      byte[] imageByte = Base64.decodeBase64(img[1]);
                      Path path = Paths.get(UPLOADED_FOLDER + documentImage.getDocId() + "_" + document.getUploadImagesPath());
                      Files.write(path, imageByte);
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
                  documentImage.setUploadImagesPath(documentImage.getDocId() + "_" + document.getUploadImagesPath());
                  documentrepository.save(documentImage);
                  status = true;
                  return status;
              }
          }
          return status;
      }
  
  }
  </code></pre>
  
  <p>Controller Class.</p>
  
  <pre><code>package com.erp.controller;
  
  import java.io.ByteArrayOutputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.ArrayList;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.http.HttpHeaders;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.security.core.Authentication;
  import org.springframework.security.core.context.SecurityContextHolder;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.multipart.MultipartFile;
  import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  
  import com.erp.model.Document;
  import com.erp.service.DocumentService;
  import com.erp.service.EmployeeService;
  import com.erp.service.TurbineService;
  import com.erp.utils.IConstant;
  
  @Controller
  @ComponentScan
  public class DocumentController {
  
      @Autowired
      DocumentService documentService;
  
      @Autowired
      TurbineService turbineService;
  
      @Autowired
      EmployeeService employeeService;
  
      @GetMapping("/addDocument/{turbine_id}")
      public String newDocument(@PathVariable Integer turbine_id, Model model) {
          Document document = new Document();
          document.setTurbine_id(turbine_id);
          Authentication auth = SecurityContextHolder.getContext().getAuthentication();
          model.addAttribute("employee", employeeService.findEmployeeByUsername(auth.getName()));
          model.addAttribute("turbine", turbineService.findTurbine(turbine_id));
          model.addAttribute("addDocument", document);
          model.addAttribute("viewDocuments", (ArrayList&lt;Document&gt;) documentService.findAllByTurbine_id(turbine_id));
          return "turbine-documents";
      }
  
      @RequestMapping(value = "/documentUpload", method = { RequestMethod.GET, RequestMethod.POST })
      private String saveUploadImages(@RequestParam("file") MultipartFile file,
              @ModelAttribute("Document") Document document, ModelMap model,
              final RedirectAttributes redirectAttributes) {
          boolean status = documentService.uploadUserImage(file, document);
          if (status) {
              model.addAttribute(IConstant.MESSAGE, IConstant.UPLOAD_IMAGE_SUCCESS_MESSAGE);
              redirectAttributes.addFlashAttribute("message", IConstant.UPLOAD_IMAGE_SUCCESS_MESSAGE);
              redirectAttributes.addFlashAttribute("alertClass", "alert-success");
          } else {
              model.addAttribute(IConstant.MESSAGE, IConstant.UPLOAD_IMAGE_FAILURE_MESSAGE);
              redirectAttributes.addFlashAttribute("message", IConstant.UPLOAD_IMAGE_FAILURE_MESSAGE);
              redirectAttributes.addFlashAttribute("alertClass", "alert-danger");
          }
  
          return "redirect:/addDocument/" + document.getTurbine_id();
      }
  
      @RequestMapping(value = "download", method = RequestMethod.GET)
      @ResponseBody
      public ResponseEntity&lt;byte[]&gt; downloadFile(@RequestParam("uploadImagesPath") String uploadImagesPath)
              throws IOException {
          String filename = "s3://elasticbeanstalk-ap-south-1-461760552509/imagesUpload/" + uploadImagesPath;
          @SuppressWarnings("resource")
          InputStream inputImage = new FileInputStream(filename);
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
          byte[] buffer = new byte[512];
          int l = inputImage.read(buffer);
          while (l &gt;= 0) {
              outputStream.write(buffer, 0, l);
              l = inputImage.read(buffer);
          }
          HttpHeaders headers = new HttpHeaders();
          headers.set("Content-Type", "image/jpeg");
          headers.set("Content-Type", "application/pdf");
          headers.set("Content-Disposition", "attachment; filename=\"" + uploadImagesPath + "");
          return new ResponseEntity&lt;byte[]&gt;(outputStream.toByteArray(), headers, HttpStatus.OK);
      }
  
  }
  </code></pre>
  
  <p>Thymeleaf page:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security"&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8" /&gt;
  &lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
  &lt;title&gt;Documents&lt;/title&gt;
  &lt;meta
      content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
      name="viewport" /&gt;
  &lt;link rel="shortcut icon" href="images/ctmi_favicon.png"
      th:href="@{/images/ctmi_favicon.png}" /&gt;
  &lt;link rel="apple-touch-icon" href="images/ctmi_favicon-57x57.png"
      th:href="@{/images/ctmi_favicon-57x57.png}" /&gt;
  &lt;link rel="apple-touch-icon" sizes="72x72"
      href="images/ctmi_favicon-72x72.png"
      th:href="@{/images/ctmi_favicon-72x72.png}" /&gt;
  &lt;link rel="apple-touch-icon" sizes="114x114"
      href="images/ctmi_favicon-114x114.png"
      th:href="@{/images/ctmi_favicon-114x114.png}" /&gt;
  
  &lt;!-- css --&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"
      th:href="@{/css/bootstrap.min.css}" /&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/font-awesome.min.css"
      th:href="@{/css/font-awesome.min.css}" /&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/jquery-ui.min.css"
      th:href="@{/css/jquery-ui.min.css}" /&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/style.css"
      th:href="@{/css/style.css}" /&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/responsive.css"
      th:href="@{/css/responsive.css}" /&gt;
  
  
  &lt;!--[if IE]&gt;
          &lt;script src="js/html5shiv.js" th:src="@{/js/html5shiv.js}" &gt;&lt;/script&gt;
      &lt;![endif]--&gt;
  
  &lt;!-- js --&gt;
  &lt;!-- js --&gt;
  &lt;script type="text/javascript" src="js/jquery.min.js"
      th:src="@{/js/jquery.min.js}"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/bootstrap.min.js"
      th:src="@{/js/bootstrap.min.js}"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/jquery-ui.min.js"
      th:src="@{/js/jquery-ui.min.js}"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/custom.js"
      th:src="@{/js/custom.js}"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body class="alBody"&gt;
      &lt;!-- Preloader --&gt;
      &lt;div class="preLoader"&gt;&lt;/div&gt;
  
      &lt;!-- Header --&gt;
      &lt;header&gt;
          &lt;div class="container"&gt;
              &lt;div class="hdrLogo"&gt;
                  &lt;img src="images/chola_turbo_logo.png"
                      th:src="@{/images/chola_turbo_logo.png}" alt="cholaturbo Logo"
                      class="logoDefault" /&gt;
              &lt;/div&gt;
              &lt;div class="hdrRight"&gt;
                  &lt;div class="hdrrInr"&gt;
                      &lt;div class="hdrrLeft"&gt;
                          &lt;ul&gt;
                              &lt;li class="logoutIcn"&gt;
                                  &lt;a href="#" th:href="@{/page/home}"&gt;
                                      &lt;i class="fa fa-home fa-7x" aria-hidden="true"&gt;&lt;/i&gt;
                                  &lt;/a&gt;
  
                              &lt;/li&gt;
                              &lt;li class="logoutIcn"&gt;
                                  &lt;a href="#" th:href="@{/employee/edit/{employee_id}(employee_id=${employee.employee_id})}" &gt;
                                      &lt;i class="fa fa-user fa-7x" aria-hidden="true"&gt;&lt;/i&gt;
                                  &lt;/a&gt;
  
                              &lt;/li&gt;
  
                              &lt;li class="logoutIcn"&gt;&lt;a href="/logout"&gt;&lt;i
                                      class="fa fa-sign-out" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
                          &lt;/ul&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/header&gt;
  
      &lt;!-- Body Content Sec --&gt;
      &lt;section class="bodyCnt"&gt;
          &lt;!-- Top Bread Sec --&gt;
          &lt;div class="topBread"&gt;
              &lt;div class="container"&gt;
                  &lt;ol class="breadcrumb"&gt;
                      &lt;li&gt;&lt;a href="#"
                          th:href="@{/client/{client_id}(client_id=${turbine.client_id})}"&gt;BACK&lt;/a&gt;&lt;/li&gt;
                      &lt;li class="active"&gt;Documents&lt;/li&gt;
                  &lt;/ol&gt;
                  &lt;div class="addProj"&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;!-- Main body page --&gt;
          &lt;div class="mbSec"&gt;
              &lt;div class="container"&gt;
                  &lt;div class="dbWrap clearfix"&gt;
  
                      &lt;div class="col-md-3"&gt;
                          &lt;div class="bsSgl"&gt;
                              &lt;div class="bsInr"&gt;
  
                                  &lt;div class="dbsHead"&gt;
                                      &lt;h4&gt;Turbine Details&lt;/h4&gt;
                                  &lt;/div&gt;
  
                                  &lt;ul class="side-menu"&gt;
                                      &lt;li&gt;&lt;a href="turbine-details-new.html"
                                          th:href="@{/turbine/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;Turbine
                                              Details &lt;/a&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;a href="turbine-engneer-assigned.html"
                                          th:href="@{/AddAssignTurbine/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;Engneer
                                              Assigned&lt;/a&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;a href="turbine-site-report.html"
                                          th:href="@{/addAddService/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;Site
                                              Report&lt;/a&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;a href="turbine-site-readings.html"
                                          th:href="@{/readingPage/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;Site
                                              Reading&lt;/a&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;a href="turbine-material.html"
                                          th:href="@{/material/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;Materials And Spares&lt;/a&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;a href="turbine-documents.html"
                                          th:href="@{/addDocument/{turbine_id}(turbine_id=${addDocument.turbine_id})}"
                                          class="active"&gt;Documents&lt;/a&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;a href="turbine-drawings.html"
                                          th:href="@{/addDrawing/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;Drawings&lt;/a&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;a href="turbine-ta-da.html"
                                          th:href="@{/AddDailyAllowance/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;TA
                                              DA Bill&lt;/a&gt;&lt;/li&gt;
                                      &lt;li sec:authorize="hasAuthority('ADMIN')"&gt;&lt;a
                                          href="turbine-man-days-expenses.html"
                                          th:href="@{/ManDays/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;
                                              Man Days Expenses&lt;/a&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;a href="turbine-client-delay.html"
                                          th:href="@{/addClientDelay/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;Client
                                              Delay&lt;/a&gt;&lt;/li&gt;
                                      &lt;li sec:authorize="hasAuthority('ADMIN')"&gt;&lt;a
                                          href="turbine-client-requests.html"
                                          th:href="@{/AddClientResponse/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;Client
                                              Requests&lt;/a&gt;&lt;/li&gt;
                                      &lt;li&gt;&lt;a href="turbine-generate-report"
                                          th:href="@{/generateReportPage/{turbine_id}(turbine_id=${addDocument.turbine_id})}"&gt;Generate
                                              Report&lt;/a&gt;&lt;/li&gt;
                                  &lt;/ul&gt;
                              &lt;/div&gt;
  
                          &lt;/div&gt;
  
                      &lt;/div&gt;
                      &lt;!-- end left bar --&gt;
  
                      &lt;div class="col-md-9 bsSgl"&gt;
                          &lt;div class="bsInr"&gt;
                              &lt;div class="dbsHead"&gt;
                                  &lt;h4&gt;Documents&lt;/h4&gt;
                              &lt;/div&gt;
                              &lt;div th:if="${message}" th:text="${message}"
                                  th:class="${'alert ' + alertClass}"&gt;&lt;/div&gt;
                              &lt;form class="row" action="#" th:action="@{/documentUpload}"
                                  th:object="${addDocument}" method="post"
                                  enctype="multipart/form-data"&gt;
                                  &lt;div class="bsMtr"&gt;
                                      &lt;div class="col-md-9"&gt;
                                          &lt;div class="snglInpt"&gt;
                                              &lt;input type="file" name="file"
                                                  placeholder="Upload Image" th:required="required" /&gt; &lt;input
                                                  type="hidden" th:field="*{turbine_id}" name="turbine_id"
                                                  id="turbine_id" placeholder="Turbine Id" /&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;div class="col-md-3"&gt;
                                          &lt;button class="btn btn-success" type="submit"&gt;Submit&lt;/button&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/form&gt;
                          &lt;/div&gt;
  
                          &lt;div class="clearfix"&gt;&lt;/div&gt;
  
                          &lt;div class="bsInr mrg-top-20"&gt;
                              &lt;div class="bsMtr"&gt;
                                  &lt;div class="table-responsive"&gt;
                                      &lt;table class="table" id="doc_list"&gt;
                                          &lt;tbody&gt;
                                              &lt;tr&gt;
  
                                                  &lt;td&gt;TurbineId&lt;/td&gt;
                                                  &lt;td&gt;Image&lt;/td&gt;
                                                  &lt;td&gt;Date&lt;/td&gt;
                                                  &lt;td&gt;Download Image&lt;/td&gt;
                                              &lt;/tr&gt;
                                              &lt;tr th:each="viewDocument : ${viewDocuments}"&gt;
                                                  &lt;td th:text="${viewDocument.docId}"&gt;&lt;/td&gt;
                                                  &lt;td th:text="${viewDocument.uploadImagesPath}"&gt;&lt;/td&gt;
                                                  &lt;td th:text="${viewDocument.date}"&gt;&lt;/td&gt;
                                                  &lt;td&gt;&lt;a
                                                      th:href="@{|/download?uploadImagesPath=${viewDocument.uploadImagesPath}|}"&gt;&lt;span
                                                          th:text="${viewDocument.uploadImagesPath}"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
                                              &lt;/tr&gt;
                                          &lt;/tbody&gt;
                                      &lt;/table&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
  
                      &lt;/div&gt;
                      &lt;!-- end col md 12 --&gt;
  
                  &lt;/div&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/section&gt;
  
      &lt;!-- Footer --&gt;
      &lt;footer&gt;
          &lt;div class="container"&gt;
              &lt;p&gt;Copyright © 2018 cholaturbo&lt;/p&gt;
          &lt;/div&gt;
      &lt;/footer&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Rest controller for android:</p>
  
  <pre><code>package com.erp.webService;
  
  import java.io.ByteArrayOutputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpHeaders;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.bind.annotation.RestController;
  import com.erp.model.Document;
  import com.erp.service.DocumentService;
  import com.erp.utils.IConstant;
  
  @RestController
  @RequestMapping("/api")
  public class DocumentWebService {
  
      @Autowired
      DocumentService documentService;
  
      private static String UPLOADED_FOLDER = "//var//sentora//hostdata//cholaerp//public_html//imagesUpload//";
  
      @RequestMapping(value = "uploadFile", method = RequestMethod.POST)
      public @ResponseBody Map&lt;String, Object&gt; saveUserImage(@RequestBody Document document) throws IOException {
          int turbine_id = document.getTurbine_id();
          Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
          boolean documents = documentService.uploadUserWebServiceImage(document);
          if (documents) {
              List&lt;Document&gt; list = documentService.findAllByTurbine_id(turbine_id);
              for (Document doc : list) {
                  doc.setImageBase(null);
                  doc.setUploadImagesPath(doc.getUploadImagesPath());
              }
              map.put(IConstant.RESPONSE, IConstant.RESPONSE_SUCCESS_MESSAGE);
              map.put(IConstant.MESSAGE, IConstant.UPLOAD_IMAGE_SUCCESS_MESSAGE);
              map.put(IConstant.DATA, list);
          } else {
              map.put(IConstant.RESPONSE, IConstant.RESPONSE_NO_DATA_MESSAGE);
              map.put(IConstant.MESSAGE, IConstant.UPLOAD_IMAGE_FAILURE_MESSAGE);
          }
          return map;
      }
  
      @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
      @ResponseBody
      public ResponseEntity&lt;byte[]&gt; downloadFile(@RequestParam("uploadImagesPath") String uploadImagesPath)
              throws IOException {
          String filename = "https://s3.console.aws.amazon.com//s3//buckets//elasticbeanstalk-ap-south-1-461760552509//?region=ap-south-1&amp;tab=overview//imagesUpload//" + uploadImagesPath;
          @SuppressWarnings("resource")
          InputStream inputImage = new FileInputStream(filename);
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
          byte[] buffer = new byte[512];
          int l = inputImage.read(buffer);
          while (l &gt;= 0) {
              outputStream.write(buffer, 0, l);
              l = inputImage.read(buffer);
          }
          HttpHeaders headers = new HttpHeaders();
          headers.set("Content-Type", "image/jpeg");
          headers.set("Content-Type", "application/pdf");
          headers.set("Content-Disposition", "attachment; filename=\"" + uploadImagesPath + "");
          return new ResponseEntity&lt;byte[]&gt;(outputStream.toByteArray(), headers, HttpStatus.OK);
      }
  
      @GetMapping(value = "/getAllImages", produces = "application/json")
      public List&lt;Document&gt; getAllImages() {
          return (List&lt;Document&gt;) documentService.getAllImages();
      }
  
      @GetMapping(value = "/getAllDocument/{turbine_id}", produces = "application/json")
      public List&lt;Document&gt; getAllByTurbineId(@PathVariable(value = "turbine_id") int turbine_id)  {
          return (List&lt;Document&gt;) documentService.findAllByTurbine_id(turbine_id);
      }
  }
  </code></pre>