使用mongoskin& amp;基于_ID从GridFS读取文件的NodeJS

时间:2015-06-21 23:34:45

标签: mongodb mongoskin

我在基于nodejs的应用程序中使用mongoskin。我使用GridFS来上传文件。我可以使用“文件名”上传和读取它,但我想用_id读回来。我能怎么做?以下是代码详细信息。

根据文件名读取文件的工作代码:

exports.previewFile = function (req, res) {
    var contentId = req.params.contentid;
    var gs = DBModule.db.gridStore('69316_103528209714703_155822_n.jpg', 'r');
    gs.read(function (err, data) {
        if (!err) {
            res.setHeader('Content-Type', gs.contentType);
            res.end(data);
        } else {
            log.error({err: err}, 'Failed to read the content for id '+contentId);
            res.status(constants.HTTP_CODE_INTERNAL_SERVER_ERROR);
            res.json({error: err});
        }
    });
};

如何修改此代码以使其基于id?

工作

1 个答案:

答案 0 :(得分:0)

几次击中&试用以下代码有效。这是惊喜bcz输入参数似乎搜索所有字段。

Dim shtSheet1 As String
Dim dict As Object
Dim myCell As Range
Dim firstHeaderCell As Range


shtSheet1 = "Test"

Set dict = CreateObject("Scripting.Dictionary")

Set firstHeaderCell = Range("A1")

'Iterate across column headers only
For Each myCell In Range(firstHeaderCell, _
                         Cells(firstHeaderCell.Row, _
                               firstHeaderCell.Column + firstHeaderCell.CurrentRegion.Columns.Count - 1))

  'Add it to the dictionary if it isn't there (this future proofs the code)
  If Not dict.Exists(myCell.Value) Then
    dict.Add myCell.Value, 0
  End If

  'Use worksheet function COUNTIF to count number of instances of column header value in the column
  dict(myCell.Value) = WorksheetFunction.CountIf(Range(Cells(firstHeaderCell.Row + 1, myCell.Column), _
                                                       Cells(firstHeaderCell.CurrentRegion.Rows.Count - 1, firstHeaderCell.Column)), _
                                                  myCell.Value)

Next
相关问题