MongoDB的GridFS – 它是文件名或文件名

请从http://mongoexplorer.com/看下面的图片:

http://mongoexplorer.com/

我一直在努力通过GridFS,参考https://github.com/jamescarr/nodejs-mongodb-streaming 。 我上传的文件很好地返回,通过下面的get函数返回的stream看起来是正确的。

var gridfs = (function () { function gridfs() { } gridfs.get = function (id, fn) { var db, store; db = mongoose.connection.db; id = new ObjectID(id); store = new GridStore(db, id, "r", { root: "fs" }); return store.open(function (err, store) { if (err) { return fn(err); } return fn(null, store); }); }; return gridfs; })(); 

使用http://mongoexplorer.com/我将file upload到GridFS中进行testing,但是当我使用上面的节点代码来检索它们时,它们似乎被破坏了。

那是当我注意到文件名/文件名的东西。 在这里看/node_modules/mongodb/lib/mongodb/gridfs/gridstore.js我看到文件名的引用小写'N',但在我的GridFS中,它是一个大写'N'的文件名。

好吧,只是为了踢腿,我在GridFS中把它改成了小写,但是在检索上传的文件时,我仍然在stream(上面的节点代码)中出现了一些错误。 点击另存为…在http://mongoexplorer.com/ ,但是带回我的罚款只是完美的。

回到我的问题,(因为我的testing似乎没有certificate任何东西),我想知道是哪一个:小写'N'的文件名,或帽'N'的文件名?

请使用最新的mongodb本地驱动程序,因为GridFS有很多修复程序,在testingGridFS的streamtesting时,驱动程序的github目录中还有很多示例。

文档在

http://mongodb.github.com/node-mongodb-native

一般来说,如果你使用核心function,像使用驱动程序那样使用核心function,那么驱动程序就像你使用的驱动程序一样,可以解释你的腐败问题。

另一个Windows工具nl。 MongoVue也查找文件名而不是文件名 。 我会说,答案更可能是文件名而不是文件名。


从GridStore中检索小的Windows文件,我发现了一个错误,但我不知道如何解决它。 我猜一定有一些像Chunk.CurrentSize之类的值,但看本地节点mongo驱动程序中的chunk.js文件https://github.com/mongodb/node-mongodb-native/blob/master/lib /mongodb/gridfs/chunk.js ,我做了以下…

我find了这个:

 Chunk.prototype.readSlice = function(length) { if ((this.length() - this.internalPosition + 1) >= length) { var data = null; if (this.data.buffer != null) { //Pure BSON data = this.data.buffer.slice(this.internalPosition, this.internalPosition + length); } else { //Native BSON data = new Buffer(length); length = this.data.readInto(data, this.internalPosition); } this.internalPosition = this.internalPosition + length; return data; } else { return null; } }; 

并提出以下build议

 data = this.data.buffer.slice(this.internalPosition, this.internalPosition + length); 

进入这个if语句(1024 * 256是来自Chunk.DEFAULT_CHUNK_SIZE = 1024 * 256的值;)

  if (this.data.buffer != null) { //Pure BSON if (this.data.buffer.length > 1024 * 256) { // move to here } else { data = this.data.buffer; } 

像这样:

 Chunk.prototype.readSlice = function(length) { if ((this.length() - this.internalPosition + 1) >= length) { var data = null; if (this.data.buffer != null) { //Pure BSON if (this.data.buffer.length > 1024 * 256) { data = this.data.buffer.slice(this.internalPosition, this.internalPosition + length); } else { data = this.data.buffer; } } else { //Native BSON data = new Buffer(length); length = this.data.readInto(data, this.internalPosition); } this.internalPosition = this.internalPosition + length; return data; } else { return null; } }; 

Windows文件小于块大小的问题已解决,但这不是最优雅的解决scheme。 我想提出这个答案,但我意识到使用硬编码的默认块大小不是dynamic值,这将使这个解决scheme更less;-)