File tree Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 11const express = require ( 'express' ) ;
22const 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
1919router . 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} ) ;
You can’t perform that action at this time.
0 commit comments