提交 6ab318b9 编写于 作者: S Sercan

resolves #105

上级 9cfc1bfa
......@@ -19,7 +19,7 @@
</div>
</div>
{{> selector}}
{{> selector hide=true}}
{{>uploadFile}}
......
......@@ -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()
}));
}
},
......
......@@ -3,8 +3,11 @@
<label class="col-lg-1 control-label">Selector</label>
<div id="divSelector" class="col-lg-11">
<textarea id="txtSelector" class="form-control"></textarea>
<span class="help-block m-b-none">By default, valid <strong>ObjectID</strong> and <strong>ISODate (YYYY-MM-DD
{{#if hide}}
{{else}}
<span class="help-block m-b-none">By default, valid <strong>ObjectID</strong> and <strong>ISODate (YYYY-MM-DD
HH:mm:ss)</strong> strings are being converted into MongoDB objects, <strong>uncheck</strong> right upper corner checkboxes to change this behaviour</span>
{{/if}}
</div>
</div>
</template>
\ No newline at end of file
/**
* 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册