Skip to content

Commit b755d20

Browse files
committed
set proper filename when downloading
1 parent b53ddab commit b755d20

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
- [x] send 404 for unknown links and don't log
3131
- [x] generate preview page as blurry jpeg. extracting the first page from the PDF does not reduce file size much
32-
- [ ] set proper filename for download
32+
- [x] set proper filename for download
3333

3434
- [ ] circle e2e test
3535

src/main/java/com/headissue/servlet/SeePdfs.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ public SeePdfs(
6363
}
6464

6565
@Override
66-
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
66+
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
67+
throws IOException, ServletException {
6768
String accessId = getAccessId(req);
6869
Path accessYaml = getAccessYaml(accessId);
6970
if (Files.notExists(accessYaml)) {
70-
req.getRequestDispatcher("/404").forward(req, resp);
71-
return;
71+
req.getRequestDispatcher("/404").forward(req, resp);
72+
return;
7273
}
7374
AccessRule accessRule = yaml.loadAs(new FileInputStream(accessYaml.toFile()), AccessRule.class);
7475
if (isExpired(accessYaml)) {
@@ -147,6 +148,7 @@ private void writePdfFileResponse(
147148
reportDownload(accessRule, visitor);
148149
byte[] buffer = new byte[1024];
149150
resp.setContentType("application/pdf");
151+
resp.setHeader("Content-Disposition", String.format("filename=\"%s\"", pdfPath.getFileName()));
150152
try (InputStream in = Files.newInputStream(pdfPath)) {
151153
OutputStream output = resp.getOutputStream();
152154
for (int length; (length = in.read(buffer)) > 0; ) {

0 commit comments

Comments
 (0)