add header: content disposition

This commit is contained in:
Michele Artini 2023-12-14 13:41:32 +01:00
parent a0e7425379
commit a88d0e59f6
1 changed files with 6 additions and 7 deletions

View File

@ -37,17 +37,16 @@ public class PublicApiController {
res.sendError(HttpStatus.BAD_REQUEST.value(), "Invalid year");
}
final String filename = String.format("%s_%s_%s.log", year, month, country);
res.setContentType(MediaType.TEXT_PLAIN.getType());
final ServletOutputStream out = res.getOutputStream();
res.setHeader("Content-Disposition", "attachment; filename=" + filename);
dbUtils.obtainLogEntries(year, month, country).forEach(s -> {
try {
try (final ServletOutputStream out = res.getOutputStream()) {
for (final String s : dbUtils.obtainLogEntries(year, month, country)) {
IOUtils.write(s, out, StandardCharsets.UTF_8);
} catch (final IOException e) {
throw new RuntimeException(e);
}
});
}
}
}