Skip to content

Commit

Permalink
examples: demonstrate sub directory download
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Dec 16, 2021
1 parent b5121a6 commit c0e5dc1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions examples/downloads/files/notes/groceries.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* milk
* eggs
* bread
11 changes: 6 additions & 5 deletions examples/downloads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ var path = require('path');
var app = module.exports = express();

app.get('/', function(req, res){
res.send('<ul>'
+ '<li>Download <a href="/files/amazing.txt">amazing.txt</a>.</li>'
+ '<li>Download <a href="/files/missing.txt">missing.txt</a>.</li>'
+ '<li>Download <a href="/files/CCTV大赛上海分赛区.txt">CCTV大赛上海分赛区.txt</a>.</li>'
+ '</ul>');
res.send('<ul>' +
'<li>Download <a href="/files/notes/groceries.txt">notes/groceries.txt</a>.</li>' +
'<li>Download <a href="/files/amazing.txt">amazing.txt</a>.</li>' +
'<li>Download <a href="/files/missing.txt">missing.txt</a>.</li>' +
'<li>Download <a href="/files/CCTV大赛上海分赛区.txt">CCTV大赛上海分赛区.txt</a>.</li>' +
'</ul>')
});

// /files/* is accessed via req.params[0]
Expand Down
9 changes: 9 additions & 0 deletions test/acceptance/downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ describe('downloads', function(){
})
})

describe('GET /files/notes/groceries.txt', function () {
it('should have a download header', function (done) {
request(app)
.get('/files/notes/groceries.txt')
.expect('Content-Disposition', 'attachment; filename="groceries.txt"')
.expect(200, done)
})
})

describe('GET /files/amazing.txt', function(){
it('should have a download header', function(done){
request(app)
Expand Down

0 comments on commit c0e5dc1

Please sign in to comment.