unable to get excel file in response entity in spring boot rest controller












1















I am exporting my database data to an excel sheet using spring boot. I am able to create and download the excel sheet in my browser but i am unable to send that excel file in my Response Entity .When I send my excel download url through postman I am getting some raw responses ,how can I can convert it so that it displays the contents of the file to the client.
Here is my code. Can you please suggest me where i am doing wrong.



here is my service class which generate excel and store it in byte array.



    public byte exportToExcelFile() throws IOException {
List<Employee> list = dao.getEmployee();

XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Employee");
XSSFRow row = sheet.createRow(1);

// create style for header cells
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontName("Arial");
style.setFillForegroundColor(HSSFColor.BLUE.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.WHITE.index);
style.setFont(font);

// create header row
XSSFRow header = sheet.createRow(0);

header.createCell(0).setCellValue("sl nO");
header.getCell(0).setCellStyle(style);

header.createCell(1).setCellValue("Name");
header.getCell(1).setCellStyle(style);

header.createCell(2).setCellValue("Email");
header.getCell(2).setCellStyle(style);

header.createCell(3).setCellValue("Salary");
header.getCell(3).setCellStyle(style);
int rowCount = 1;

for (Employee emp : list) {
XSSFRow aRow = sheet.createRow(rowCount++);
aRow.createCell(0).setCellValue(emp.getId());
aRow.createCell(1).setCellValue(emp.getName());
aRow.createCell(2).setCellValue(emp.getEmail());
aRow.createCell(3).setCellValue(emp.getSalary());
}

ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
workbook.write(bos);
} finally {
bos.close();
}
byte bytes = bos.toByteArray();
// FileOutputStream out = new FileOutputStream(new File("employee.xlsx"));
//workbook.write(out);
//out.close();
System.out.println("exceldatabase.xlsx written successfully");
return bytes;
}


here is my rest controller to download excel.



@RestController
public class MyController {
@Autowired
EmployeeService service;

@GetMapping(value = "/exportExcel")
public ResponseEntity exportEmployeeExcel(HttpServletResponse response) throws IOException {
byte excelContent = service.exportToExcelFile();
if (excelContent.length != 0) {

response.setContentType("application/ms-excel");
response.setHeader("Content-disposition", "attachment; filename=myfile.xls");

return new ResponseEntity(excelContent, HttpStatus.OK);

} else {

return new ResponseEntity("download fail", HttpStatus.NO_CONTENT);
}
}


}










share|improve this question



























    1















    I am exporting my database data to an excel sheet using spring boot. I am able to create and download the excel sheet in my browser but i am unable to send that excel file in my Response Entity .When I send my excel download url through postman I am getting some raw responses ,how can I can convert it so that it displays the contents of the file to the client.
    Here is my code. Can you please suggest me where i am doing wrong.



    here is my service class which generate excel and store it in byte array.



        public byte exportToExcelFile() throws IOException {
    List<Employee> list = dao.getEmployee();

    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("Employee");
    XSSFRow row = sheet.createRow(1);

    // create style for header cells
    CellStyle style = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setFontName("Arial");
    style.setFillForegroundColor(HSSFColor.BLUE.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setColor(HSSFColor.WHITE.index);
    style.setFont(font);

    // create header row
    XSSFRow header = sheet.createRow(0);

    header.createCell(0).setCellValue("sl nO");
    header.getCell(0).setCellStyle(style);

    header.createCell(1).setCellValue("Name");
    header.getCell(1).setCellStyle(style);

    header.createCell(2).setCellValue("Email");
    header.getCell(2).setCellStyle(style);

    header.createCell(3).setCellValue("Salary");
    header.getCell(3).setCellStyle(style);
    int rowCount = 1;

    for (Employee emp : list) {
    XSSFRow aRow = sheet.createRow(rowCount++);
    aRow.createCell(0).setCellValue(emp.getId());
    aRow.createCell(1).setCellValue(emp.getName());
    aRow.createCell(2).setCellValue(emp.getEmail());
    aRow.createCell(3).setCellValue(emp.getSalary());
    }

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
    workbook.write(bos);
    } finally {
    bos.close();
    }
    byte bytes = bos.toByteArray();
    // FileOutputStream out = new FileOutputStream(new File("employee.xlsx"));
    //workbook.write(out);
    //out.close();
    System.out.println("exceldatabase.xlsx written successfully");
    return bytes;
    }


    here is my rest controller to download excel.



    @RestController
    public class MyController {
    @Autowired
    EmployeeService service;

    @GetMapping(value = "/exportExcel")
    public ResponseEntity exportEmployeeExcel(HttpServletResponse response) throws IOException {
    byte excelContent = service.exportToExcelFile();
    if (excelContent.length != 0) {

    response.setContentType("application/ms-excel");
    response.setHeader("Content-disposition", "attachment; filename=myfile.xls");

    return new ResponseEntity(excelContent, HttpStatus.OK);

    } else {

    return new ResponseEntity("download fail", HttpStatus.NO_CONTENT);
    }
    }


    }










    share|improve this question

























      1












      1








      1








      I am exporting my database data to an excel sheet using spring boot. I am able to create and download the excel sheet in my browser but i am unable to send that excel file in my Response Entity .When I send my excel download url through postman I am getting some raw responses ,how can I can convert it so that it displays the contents of the file to the client.
      Here is my code. Can you please suggest me where i am doing wrong.



      here is my service class which generate excel and store it in byte array.



          public byte exportToExcelFile() throws IOException {
      List<Employee> list = dao.getEmployee();

      XSSFWorkbook workbook = new XSSFWorkbook();
      XSSFSheet sheet = workbook.createSheet("Employee");
      XSSFRow row = sheet.createRow(1);

      // create style for header cells
      CellStyle style = workbook.createCellStyle();
      Font font = workbook.createFont();
      font.setFontName("Arial");
      style.setFillForegroundColor(HSSFColor.BLUE.index);
      style.setFillPattern(CellStyle.SOLID_FOREGROUND);
      font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
      font.setColor(HSSFColor.WHITE.index);
      style.setFont(font);

      // create header row
      XSSFRow header = sheet.createRow(0);

      header.createCell(0).setCellValue("sl nO");
      header.getCell(0).setCellStyle(style);

      header.createCell(1).setCellValue("Name");
      header.getCell(1).setCellStyle(style);

      header.createCell(2).setCellValue("Email");
      header.getCell(2).setCellStyle(style);

      header.createCell(3).setCellValue("Salary");
      header.getCell(3).setCellStyle(style);
      int rowCount = 1;

      for (Employee emp : list) {
      XSSFRow aRow = sheet.createRow(rowCount++);
      aRow.createCell(0).setCellValue(emp.getId());
      aRow.createCell(1).setCellValue(emp.getName());
      aRow.createCell(2).setCellValue(emp.getEmail());
      aRow.createCell(3).setCellValue(emp.getSalary());
      }

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      try {
      workbook.write(bos);
      } finally {
      bos.close();
      }
      byte bytes = bos.toByteArray();
      // FileOutputStream out = new FileOutputStream(new File("employee.xlsx"));
      //workbook.write(out);
      //out.close();
      System.out.println("exceldatabase.xlsx written successfully");
      return bytes;
      }


      here is my rest controller to download excel.



      @RestController
      public class MyController {
      @Autowired
      EmployeeService service;

      @GetMapping(value = "/exportExcel")
      public ResponseEntity exportEmployeeExcel(HttpServletResponse response) throws IOException {
      byte excelContent = service.exportToExcelFile();
      if (excelContent.length != 0) {

      response.setContentType("application/ms-excel");
      response.setHeader("Content-disposition", "attachment; filename=myfile.xls");

      return new ResponseEntity(excelContent, HttpStatus.OK);

      } else {

      return new ResponseEntity("download fail", HttpStatus.NO_CONTENT);
      }
      }


      }










      share|improve this question














      I am exporting my database data to an excel sheet using spring boot. I am able to create and download the excel sheet in my browser but i am unable to send that excel file in my Response Entity .When I send my excel download url through postman I am getting some raw responses ,how can I can convert it so that it displays the contents of the file to the client.
      Here is my code. Can you please suggest me where i am doing wrong.



      here is my service class which generate excel and store it in byte array.



          public byte exportToExcelFile() throws IOException {
      List<Employee> list = dao.getEmployee();

      XSSFWorkbook workbook = new XSSFWorkbook();
      XSSFSheet sheet = workbook.createSheet("Employee");
      XSSFRow row = sheet.createRow(1);

      // create style for header cells
      CellStyle style = workbook.createCellStyle();
      Font font = workbook.createFont();
      font.setFontName("Arial");
      style.setFillForegroundColor(HSSFColor.BLUE.index);
      style.setFillPattern(CellStyle.SOLID_FOREGROUND);
      font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
      font.setColor(HSSFColor.WHITE.index);
      style.setFont(font);

      // create header row
      XSSFRow header = sheet.createRow(0);

      header.createCell(0).setCellValue("sl nO");
      header.getCell(0).setCellStyle(style);

      header.createCell(1).setCellValue("Name");
      header.getCell(1).setCellStyle(style);

      header.createCell(2).setCellValue("Email");
      header.getCell(2).setCellStyle(style);

      header.createCell(3).setCellValue("Salary");
      header.getCell(3).setCellStyle(style);
      int rowCount = 1;

      for (Employee emp : list) {
      XSSFRow aRow = sheet.createRow(rowCount++);
      aRow.createCell(0).setCellValue(emp.getId());
      aRow.createCell(1).setCellValue(emp.getName());
      aRow.createCell(2).setCellValue(emp.getEmail());
      aRow.createCell(3).setCellValue(emp.getSalary());
      }

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      try {
      workbook.write(bos);
      } finally {
      bos.close();
      }
      byte bytes = bos.toByteArray();
      // FileOutputStream out = new FileOutputStream(new File("employee.xlsx"));
      //workbook.write(out);
      //out.close();
      System.out.println("exceldatabase.xlsx written successfully");
      return bytes;
      }


      here is my rest controller to download excel.



      @RestController
      public class MyController {
      @Autowired
      EmployeeService service;

      @GetMapping(value = "/exportExcel")
      public ResponseEntity exportEmployeeExcel(HttpServletResponse response) throws IOException {
      byte excelContent = service.exportToExcelFile();
      if (excelContent.length != 0) {

      response.setContentType("application/ms-excel");
      response.setHeader("Content-disposition", "attachment; filename=myfile.xls");

      return new ResponseEntity(excelContent, HttpStatus.OK);

      } else {

      return new ResponseEntity("download fail", HttpStatus.NO_CONTENT);
      }
      }


      }







      excel rest spring-boot export






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 10:01









      Lipsa PatraLipsa Patra

      164




      164
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Could you try this :



          @CrossOrigin
          @ResponseBody
          @GetMapping(value = "/exportExcel")
          public ResponseEntity<InputStreamResource> exportEmployeeExcel(HttpServletResponse response) throws IOException {
          byte excelContent = service.exportToExcelFile();
          if (excelContent.length != 0) {
          String fileName = "example.xlsx";
          MediaType mediaType = MediaType.parseMediaType("application/vnd.ms-excel");
          File file = new File(fileName);
          FileUtils.writeByteArrayToFile(file, excelContent);
          InputStreamResource resource = new InputStreamResource(new FileInputStream(file));

          return ResponseEntity.ok()
          // Content-Disposition
          .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + file.getName())
          // Content-Type
          .contentType(mediaType)
          // Contet-Length
          .contentLength(file.length()) //
          .body(resource);
          }else{
          return null; // you can return what you want !
          }

          }





          share|improve this answer
























          • Thanks for your response. I have tried the above code in my application. I am using FileUtils class of org.apache.tomcat.util.http.fileupload.FileUtils. but the method writeByteArrayToFile(file,byte) throwing error in my application saying The method writeByteArrayToFile(File, byte) is undefined for the type FileUtils.

            – Lipsa Patra
            Nov 22 '18 at 16:18











          • kindly suggest me how to overcome this error. thanks in advance.

            – Lipsa Patra
            Nov 22 '18 at 16:19











          • Sorry , I have added the wrong jar file i.e org.apache.tomcat.util.http.fileupload.FileUtils . Later I have corrected that to org.apache.commons.io.FileUtils and run the application. my excel file is downloaded bt when i fire the request on postman in the response i am getting some raw data instead of excel file.so How I will get that as I want to return the excel in rest api.

            – Lipsa Patra
            Nov 22 '18 at 16:43











          • @LipsaPatra Well done of course you have to use org.apache.commons.io.FileUtils, Can you tag your question answered ?

            – TinyOS
            Nov 22 '18 at 16:47











          • I am unable get excel file in my rest api. I am able to generate excel file but in my rest controller i am unable to provide that excel file to the front end. How Could I achieve that.

            – Lipsa Patra
            Nov 23 '18 at 5:01











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428354%2funable-to-get-excel-file-in-response-entity-in-spring-boot-rest-controller%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Could you try this :



          @CrossOrigin
          @ResponseBody
          @GetMapping(value = "/exportExcel")
          public ResponseEntity<InputStreamResource> exportEmployeeExcel(HttpServletResponse response) throws IOException {
          byte excelContent = service.exportToExcelFile();
          if (excelContent.length != 0) {
          String fileName = "example.xlsx";
          MediaType mediaType = MediaType.parseMediaType("application/vnd.ms-excel");
          File file = new File(fileName);
          FileUtils.writeByteArrayToFile(file, excelContent);
          InputStreamResource resource = new InputStreamResource(new FileInputStream(file));

          return ResponseEntity.ok()
          // Content-Disposition
          .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + file.getName())
          // Content-Type
          .contentType(mediaType)
          // Contet-Length
          .contentLength(file.length()) //
          .body(resource);
          }else{
          return null; // you can return what you want !
          }

          }





          share|improve this answer
























          • Thanks for your response. I have tried the above code in my application. I am using FileUtils class of org.apache.tomcat.util.http.fileupload.FileUtils. but the method writeByteArrayToFile(file,byte) throwing error in my application saying The method writeByteArrayToFile(File, byte) is undefined for the type FileUtils.

            – Lipsa Patra
            Nov 22 '18 at 16:18











          • kindly suggest me how to overcome this error. thanks in advance.

            – Lipsa Patra
            Nov 22 '18 at 16:19











          • Sorry , I have added the wrong jar file i.e org.apache.tomcat.util.http.fileupload.FileUtils . Later I have corrected that to org.apache.commons.io.FileUtils and run the application. my excel file is downloaded bt when i fire the request on postman in the response i am getting some raw data instead of excel file.so How I will get that as I want to return the excel in rest api.

            – Lipsa Patra
            Nov 22 '18 at 16:43











          • @LipsaPatra Well done of course you have to use org.apache.commons.io.FileUtils, Can you tag your question answered ?

            – TinyOS
            Nov 22 '18 at 16:47











          • I am unable get excel file in my rest api. I am able to generate excel file but in my rest controller i am unable to provide that excel file to the front end. How Could I achieve that.

            – Lipsa Patra
            Nov 23 '18 at 5:01
















          0














          Could you try this :



          @CrossOrigin
          @ResponseBody
          @GetMapping(value = "/exportExcel")
          public ResponseEntity<InputStreamResource> exportEmployeeExcel(HttpServletResponse response) throws IOException {
          byte excelContent = service.exportToExcelFile();
          if (excelContent.length != 0) {
          String fileName = "example.xlsx";
          MediaType mediaType = MediaType.parseMediaType("application/vnd.ms-excel");
          File file = new File(fileName);
          FileUtils.writeByteArrayToFile(file, excelContent);
          InputStreamResource resource = new InputStreamResource(new FileInputStream(file));

          return ResponseEntity.ok()
          // Content-Disposition
          .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + file.getName())
          // Content-Type
          .contentType(mediaType)
          // Contet-Length
          .contentLength(file.length()) //
          .body(resource);
          }else{
          return null; // you can return what you want !
          }

          }





          share|improve this answer
























          • Thanks for your response. I have tried the above code in my application. I am using FileUtils class of org.apache.tomcat.util.http.fileupload.FileUtils. but the method writeByteArrayToFile(file,byte) throwing error in my application saying The method writeByteArrayToFile(File, byte) is undefined for the type FileUtils.

            – Lipsa Patra
            Nov 22 '18 at 16:18











          • kindly suggest me how to overcome this error. thanks in advance.

            – Lipsa Patra
            Nov 22 '18 at 16:19











          • Sorry , I have added the wrong jar file i.e org.apache.tomcat.util.http.fileupload.FileUtils . Later I have corrected that to org.apache.commons.io.FileUtils and run the application. my excel file is downloaded bt when i fire the request on postman in the response i am getting some raw data instead of excel file.so How I will get that as I want to return the excel in rest api.

            – Lipsa Patra
            Nov 22 '18 at 16:43











          • @LipsaPatra Well done of course you have to use org.apache.commons.io.FileUtils, Can you tag your question answered ?

            – TinyOS
            Nov 22 '18 at 16:47











          • I am unable get excel file in my rest api. I am able to generate excel file but in my rest controller i am unable to provide that excel file to the front end. How Could I achieve that.

            – Lipsa Patra
            Nov 23 '18 at 5:01














          0












          0








          0







          Could you try this :



          @CrossOrigin
          @ResponseBody
          @GetMapping(value = "/exportExcel")
          public ResponseEntity<InputStreamResource> exportEmployeeExcel(HttpServletResponse response) throws IOException {
          byte excelContent = service.exportToExcelFile();
          if (excelContent.length != 0) {
          String fileName = "example.xlsx";
          MediaType mediaType = MediaType.parseMediaType("application/vnd.ms-excel");
          File file = new File(fileName);
          FileUtils.writeByteArrayToFile(file, excelContent);
          InputStreamResource resource = new InputStreamResource(new FileInputStream(file));

          return ResponseEntity.ok()
          // Content-Disposition
          .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + file.getName())
          // Content-Type
          .contentType(mediaType)
          // Contet-Length
          .contentLength(file.length()) //
          .body(resource);
          }else{
          return null; // you can return what you want !
          }

          }





          share|improve this answer













          Could you try this :



          @CrossOrigin
          @ResponseBody
          @GetMapping(value = "/exportExcel")
          public ResponseEntity<InputStreamResource> exportEmployeeExcel(HttpServletResponse response) throws IOException {
          byte excelContent = service.exportToExcelFile();
          if (excelContent.length != 0) {
          String fileName = "example.xlsx";
          MediaType mediaType = MediaType.parseMediaType("application/vnd.ms-excel");
          File file = new File(fileName);
          FileUtils.writeByteArrayToFile(file, excelContent);
          InputStreamResource resource = new InputStreamResource(new FileInputStream(file));

          return ResponseEntity.ok()
          // Content-Disposition
          .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + file.getName())
          // Content-Type
          .contentType(mediaType)
          // Contet-Length
          .contentLength(file.length()) //
          .body(resource);
          }else{
          return null; // you can return what you want !
          }

          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 13:24









          TinyOSTinyOS

          92311029




          92311029













          • Thanks for your response. I have tried the above code in my application. I am using FileUtils class of org.apache.tomcat.util.http.fileupload.FileUtils. but the method writeByteArrayToFile(file,byte) throwing error in my application saying The method writeByteArrayToFile(File, byte) is undefined for the type FileUtils.

            – Lipsa Patra
            Nov 22 '18 at 16:18











          • kindly suggest me how to overcome this error. thanks in advance.

            – Lipsa Patra
            Nov 22 '18 at 16:19











          • Sorry , I have added the wrong jar file i.e org.apache.tomcat.util.http.fileupload.FileUtils . Later I have corrected that to org.apache.commons.io.FileUtils and run the application. my excel file is downloaded bt when i fire the request on postman in the response i am getting some raw data instead of excel file.so How I will get that as I want to return the excel in rest api.

            – Lipsa Patra
            Nov 22 '18 at 16:43











          • @LipsaPatra Well done of course you have to use org.apache.commons.io.FileUtils, Can you tag your question answered ?

            – TinyOS
            Nov 22 '18 at 16:47











          • I am unable get excel file in my rest api. I am able to generate excel file but in my rest controller i am unable to provide that excel file to the front end. How Could I achieve that.

            – Lipsa Patra
            Nov 23 '18 at 5:01



















          • Thanks for your response. I have tried the above code in my application. I am using FileUtils class of org.apache.tomcat.util.http.fileupload.FileUtils. but the method writeByteArrayToFile(file,byte) throwing error in my application saying The method writeByteArrayToFile(File, byte) is undefined for the type FileUtils.

            – Lipsa Patra
            Nov 22 '18 at 16:18











          • kindly suggest me how to overcome this error. thanks in advance.

            – Lipsa Patra
            Nov 22 '18 at 16:19











          • Sorry , I have added the wrong jar file i.e org.apache.tomcat.util.http.fileupload.FileUtils . Later I have corrected that to org.apache.commons.io.FileUtils and run the application. my excel file is downloaded bt when i fire the request on postman in the response i am getting some raw data instead of excel file.so How I will get that as I want to return the excel in rest api.

            – Lipsa Patra
            Nov 22 '18 at 16:43











          • @LipsaPatra Well done of course you have to use org.apache.commons.io.FileUtils, Can you tag your question answered ?

            – TinyOS
            Nov 22 '18 at 16:47











          • I am unable get excel file in my rest api. I am able to generate excel file but in my rest controller i am unable to provide that excel file to the front end. How Could I achieve that.

            – Lipsa Patra
            Nov 23 '18 at 5:01

















          Thanks for your response. I have tried the above code in my application. I am using FileUtils class of org.apache.tomcat.util.http.fileupload.FileUtils. but the method writeByteArrayToFile(file,byte) throwing error in my application saying The method writeByteArrayToFile(File, byte) is undefined for the type FileUtils.

          – Lipsa Patra
          Nov 22 '18 at 16:18





          Thanks for your response. I have tried the above code in my application. I am using FileUtils class of org.apache.tomcat.util.http.fileupload.FileUtils. but the method writeByteArrayToFile(file,byte) throwing error in my application saying The method writeByteArrayToFile(File, byte) is undefined for the type FileUtils.

          – Lipsa Patra
          Nov 22 '18 at 16:18













          kindly suggest me how to overcome this error. thanks in advance.

          – Lipsa Patra
          Nov 22 '18 at 16:19





          kindly suggest me how to overcome this error. thanks in advance.

          – Lipsa Patra
          Nov 22 '18 at 16:19













          Sorry , I have added the wrong jar file i.e org.apache.tomcat.util.http.fileupload.FileUtils . Later I have corrected that to org.apache.commons.io.FileUtils and run the application. my excel file is downloaded bt when i fire the request on postman in the response i am getting some raw data instead of excel file.so How I will get that as I want to return the excel in rest api.

          – Lipsa Patra
          Nov 22 '18 at 16:43





          Sorry , I have added the wrong jar file i.e org.apache.tomcat.util.http.fileupload.FileUtils . Later I have corrected that to org.apache.commons.io.FileUtils and run the application. my excel file is downloaded bt when i fire the request on postman in the response i am getting some raw data instead of excel file.so How I will get that as I want to return the excel in rest api.

          – Lipsa Patra
          Nov 22 '18 at 16:43













          @LipsaPatra Well done of course you have to use org.apache.commons.io.FileUtils, Can you tag your question answered ?

          – TinyOS
          Nov 22 '18 at 16:47





          @LipsaPatra Well done of course you have to use org.apache.commons.io.FileUtils, Can you tag your question answered ?

          – TinyOS
          Nov 22 '18 at 16:47













          I am unable get excel file in my rest api. I am able to generate excel file but in my rest controller i am unable to provide that excel file to the front end. How Could I achieve that.

          – Lipsa Patra
          Nov 23 '18 at 5:01





          I am unable get excel file in my rest api. I am able to generate excel file but in my rest controller i am unable to provide that excel file to the front end. How Could I achieve that.

          – Lipsa Patra
          Nov 23 '18 at 5:01


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428354%2funable-to-get-excel-file-in-response-entity-in-spring-boot-rest-controller%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen