From 6ab318b97d80a340a48c0468b18b29a2ffdc962d Mon Sep 17 00:00:00 2001 From: Sercan Date: Sat, 28 May 2016 10:52:39 +0300 Subject: [PATCH] resolves #105 --- .../file_management/file_management.html | 2 +- .../pages/file_management/file_management.js | 4 +- .../selector/selector.html | 5 +- lib/routers/file_management/download_file.js | 54 +++++++++++-------- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/client/views/pages/file_management/file_management.html b/client/views/pages/file_management/file_management.html index d0835b3..ea90ad8 100644 --- a/client/views/pages/file_management/file_management.html +++ b/client/views/pages/file_management/file_management.html @@ -19,7 +19,7 @@ - {{> selector}} + {{> selector hide=true}} {{>uploadFile}} diff --git a/client/views/pages/file_management/file_management.js b/client/views/pages/file_management/file_management.js index e7b30ea..f133bc7 100644 --- a/client/views/pages/file_management/file_management.js +++ b/client/views/pages/file_management/file_management.js @@ -22,9 +22,7 @@ Template.fileManagement.events({ if (fileRow) { window.open(Router.url('download', { fileId: fileRow._id, - connectionId: Session.get(Template.strSessionConnection), - bucketName: $('#txtBucketName').val(), - fileName: fileRow.filename + bucketName: $('#txtBucketName').val() })); } }, diff --git a/client/views/query_templates_common/selector/selector.html b/client/views/query_templates_common/selector/selector.html index dbdbce0..7ecf307 100644 --- a/client/views/query_templates_common/selector/selector.html +++ b/client/views/query_templates_common/selector/selector.html @@ -3,8 +3,11 @@
- By default, valid ObjectID and ISODate (YYYY-MM-DD + {{#if hide}} + {{else}} + By default, valid ObjectID and ISODate (YYYY-MM-DD HH:mm:ss) strings are being converted into MongoDB objects, uncheck right upper corner checkboxes to change this behaviour + {{/if}}
\ No newline at end of file diff --git a/lib/routers/file_management/download_file.js b/lib/routers/file_management/download_file.js index c6dcaa3..956d5f4 100644 --- a/lib/routers/file_management/download_file.js +++ b/lib/routers/file_management/download_file.js @@ -1,40 +1,48 @@ /** * Created by RSercan on 13.2.2016. */ -Router.route('/download/:connectionId/:bucketName/:fileName/:fileId', { +Router.route('/download/:bucketName/:fileId', { where: 'server', name: 'download', action: function () { var bucketName = this.params.bucketName; var fileId = this.params.fileId; - var fileName = this.params.fileName; - if (!bucketName || !fileId || !fileName) { + + if (!bucketName || !fileId) { return; } - console.log('[GridFS Query]', 'trying to download file: ' + fileId + " bucketName: " + bucketName); - - var mongodbApi = Meteor.npmRequire('mongodb'); - var that = this; - Async.runSync(function (done) { - try { - var bucket = new mongodbApi.GridFSBucket(database, {bucketName: bucketName}); - var headers = { - 'Content-type': 'application/octet-stream', - 'Content-Disposition': 'attachment; filename=' + fileName - }; - var downloadStream = bucket.openDownloadStream(new mongodbApi.ObjectID(fileId)); - that.response.writeHead(200, headers); - var pipeStream = downloadStream.pipe(that.response); - pipeStream.on('finish', function () { - done(null, null); - }); + Meteor.call('getFile', bucketName, fileId, function (err, result) { + if (err || result.error) { + Template.showMeteorFuncError(err, result, "Couldn't find file"); } - catch (ex) { - console.error('Unexpected exception during downloading file', ex); - done(new Meteor.Error('Error while fetching file ' + ex.message)); + else { + console.log('[GridFS Query]', 'trying to download file: ' + fileId + " bucketName: " + bucketName); + + var mongodbApi = Meteor.npmRequire('mongodb'); + Async.runSync(function (done) { + try { + var bucket = new mongodbApi.GridFSBucket(database, {bucketName: bucketName}); + var headers = { + 'Content-type': 'application/octet-stream', + 'Content-Disposition': 'attachment; filename=' + result.result.filename + }; + var downloadStream = bucket.openDownloadStream(new mongodbApi.ObjectID(fileId)); + that.response.writeHead(200, headers); + var pipeStream = downloadStream.pipe(that.response); + pipeStream.on('finish', function () { + done(null, null); + }); + } + catch (ex) { + console.error('Unexpected exception during downloading file', ex); + done(new Meteor.Error('Error while fetching file ' + ex.message)); + } + }); } }); + + } }); \ No newline at end of file -- GitLab