Skip to content

Commit a60407b

Browse files
committed
appfiles bug fix
1 parent 762d87c commit a60407b

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

api/app/AppFiles.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
21
/*
32
# CloudBoost - Core Engine that powers Bakend as a Service
4-
# (c) 2014 HackerBay, Inc.
3+
# (c) 2014 HackerBay, Inc.
54
# CloudBoost may be freely distributed under the Apache 2 License
65
*/
76

8-
module.exports = function() {
7+
module.exports = function() {
98

109
//get file from gridfs
11-
global.app.get('/appfile/:appId/icon', function (req, res) {
10+
global.app.get('/appfile/:appId/icon', function(req, res) {
1211

1312
console.log("++++ Stream file from gridfs++++++");
1413

1514
var appId = req.params.appId;
16-
var fileName = appId;
15+
var fileName = appId;
1716

18-
global.mongoService.document.getFile(appId,fileName).then(function(file){
17+
global.mongoService.document.getFile(appId, fileName).then(function(file) {
18+
if (!file)
19+
res.send();
1920

20-
var fileStream=global.mongoService.document.getFileStreamById(appId,file._id);
21+
var fileStream = global.mongoService.document.getFileStreamById(appId, file._id);
2122

2223
res.set('Content-Type', file.contentType);
23-
res.set('Content-Disposition', 'attachment; filename="' + file.filename + '"');
24+
res.set('Content-Disposition', 'attachment; filename="' + file.filename + '"');
25+
26+
fileStream.on("error", function(err) {
27+
res.send(500, "Got error while processing stream " + err.message);
28+
res.end();
29+
});
2430

25-
fileStream.on("error", function(err) {
26-
res.send(500, "Got error while processing stream " + err.message);
27-
res.end();
28-
});
29-
3031
fileStream.on('end', function() {
31-
res.end();
32+
res.end();
3233
});
3334

3435
fileStream.pipe(res);
3536

36-
},function(error){
37+
}, function(error) {
3738
return res.status(500).send(error);
38-
});
39+
});
3940

4041
});
41-
}
42-
42+
}

0 commit comments

Comments
 (0)