Последующий вопрос от моего last issue, который с тех пор был разрешен.Force Загрузить CSV от контроллера весны
Я пытаюсь загрузить файл через Spring @Controller
, возвращая FileSystemResource
. Я получаю действительный HTTP 200 Response и могу просматривать все содержимое файла в браузере, однако я никогда не получаю приглашение загрузить файл. Вот мой метод:
@RequestMapping(method = RequestMethod.GET, headers="Accept=*/*", value = "/download/{fileName:.+}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
public FileSystemResource download(@PathVariable String fileName, HttpServletResponse response) throws IOException {
File file = new File(path + '/' + fileName);
response.setContentLength((int)fileName.length());
response.setContentType("application/force-download");
response.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");//fileName);
return new FileSystemResource(file);
}
Из браузера:
Response Headers
Content-Disposition | attachment; filename="my_data.CSV"
Content-Length | 1712
Content-Type | text/csv
Request Headers
Accept | */*
Accept-Encoding | gzip, deflate
Accept-Language | en-US,en;q=0.5
Все кажется здесь справедливо; любая идея, почему фактический файл не возвращается? Приветствия
любые обновления? даже я столкнулся с этой же проблемой. все кажется правильным. –