Skip to content

Commit 1d6ee6d

Browse files
Support pdf url (#256)
* Add PDF suggested filename * Add pdf filename support
1 parent 17f0cde commit 1d6ee6d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

features/download/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<li><a href="#" class="init-iframe-download" data-type="json" >Init iframe JSON load</a>
2222
<li><a href="#" class="init-iframe-download" data-type="json" data-suggestedfilename="./../path/path/testComplex.json.">Init iframe JSON load, complex suggested path</a>
2323
<li><a href="#" class="init-iframe-download" data-type="pdf" >Init iframe PDF load</a>
24+
<li><a href="#" class="init-iframe-download" data-type="pdf" data-suggestedfilename="test-929_new.pdf">Init iframe PDF load, suggested filename</a>
2425
</ul>
2526
<div id="iframe-container"></div>
2627

features/download/server/routes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const express = require('express');
22
const router = express.Router();
33

4-
function downloadPDF (res) {
5-
res.download('./features/download/download.pdf');
4+
function downloadPDF (res, suggestedFilename) {
5+
res.download('./features/download/download.pdf', suggestedFilename);
66
}
77

8-
function downloadJSON (res, suggestedFilename) {
8+
function downloadJSON (res, suggestedFilename = 'data.json') {
99
const json = JSON.stringify({ example: 'test' });
1010
const buf = Buffer.from(json);
1111
res.writeHead(200, {
@@ -17,13 +17,13 @@ function downloadJSON (res, suggestedFilename) {
1717
}
1818

1919
router.get('/file/:type', (req, res) => {
20-
const suggestedFilename = req.query.suggestedFilename || 'data.json';
20+
const suggestedFilename = req.query.suggestedFilename;
2121
switch (req.params.type) {
2222
case 'json':
2323
downloadJSON(res, suggestedFilename);
2424
break;
2525
case 'pdf':
26-
downloadPDF(res);
26+
downloadPDF(res, suggestedFilename);
2727
break;
2828
}
2929
});

0 commit comments

Comments
 (0)