Set Content-Type based on the file path

This commit is contained in:
Raymond Feng 2014-01-29 22:39:01 -08:00
parent e853235e82
commit eb0d9a11bf
2 changed files with 4 additions and 0 deletions

View File

@ -116,8 +116,10 @@ exports.download = function (provider, req, res, container, file, cb) {
container: container || req && req.params.container,
remote: file || req && req.params.file
});
res.type(file);
reader.pipe(res);
reader.on('error', function (err) {
res.type('application/json');
res.send(500, { error: err });
});
}

View File

@ -48,6 +48,7 @@ describe('storage service', function () {
request('http://localhost:3000')
.get('/containers/album1/download/test.jpg')
.expect('Content-Type', 'image/jpeg')
.expect(200, function (err, res) {
done();
});
@ -57,6 +58,7 @@ describe('storage service', function () {
request('http://localhost:3000')
.get('/containers/album1/download/test_not_exist.jpg')
.expect('Content-Type', /json/)
.expect(500, function (err, res) {
assert(res.body.error);
done();