1

I have an Ajax method that calls the controller to generate a file and get its URL:

$('.export-excel').on('click', function() {
  var url = 'orders/excel';
  $.get(url).success(function(data) {
   console.log(data);
   downloadFile("files/" + data);
  }).error(function(data) {
   console.log(data);
  });
 });

And here is the controller code:

@RequestMapping(value="/excel", method=RequestMethod.GET)
@ResponseBody
public String getExcel() {
        List<Order> exportOrders=new LinkedList<Order>();
        try {
            exportOrders=orderService.get(filter);
        } catch (Exception e) {
            e.printStackTrace();
        }
        File excel=excelService.export(exportOrders, filter.getCurrency());
        FileSystemResource resource=new FileSystemResource(excel);
        return resource==null?StringUtils.EMPTY:resource.getFilename();
    }

This works fine and returns the URL of the file correctly, but when I download it. The browser can't download it and I get the error "Failed - No File" on Chrome.

The only solution to download this for me is to refresh the workspace in Eclipse, but yet I have to refresh it every time I create a new file (which is not practical).

EDIT: This question is different than sjonshon's Question since the code here applies the solutions found there but the idea is that the file doesn't exist until the workspace is refreshed.

Community
  • 1
  • 1
Ja'afar Naddaf
  • 357
  • 4
  • 13
  • It's not different. The duplicate clearly explains that you should never save files in deploy folder, along with a link which explains the reasons in detail. That link is used as duplicate of your other duplicate. By the way, on duplicates, the answer is important, not the question. Different questions can boil down to the same answer. – BalusC Nov 13 '16 at 14:15

0 Answers0