- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个使用 Mongo 和 GridFS 来存储图像的 nodejs 应用程序。我正在尝试通过 Node.js(使用 express 框架)将这些图像显示到浏览器。
我目前正在使用:
res.writeHead(200, {'Content-Type': 'image/jpeg' });
res.end(imageStore.currentChunk.data.buffer, 'binary');
imageStore 是创建新的 GridStore 并调用 gridStore.open(...) 后的 gridStore 对象
var gridStore = new GridStore(self.collection.db, doc._id, doc.filename, 'r', {
chunk_size: doc.chunkSize
});
gridStore.open(callback);
我敢肯定这不是正确的方法,它显示的图像有问题。有什么建议吗?
谢谢!
编辑:
更新到 mongodb native 1.0.2 后,我尝试使用流式传输数据:
res.contentType("image/jpeg");
var imageStream = imageStore.stream(true);
imageStream.pipe(res);
imageStore是使用gridStore.open(function(err, imageStore){ })
之后的对象
最佳答案
确保您使用的是驱动程序的 1.0.1,并使用 http 请求的管道来流式传输数据,下面的示例是对文件执行此操作。在 1.1 中,它会变得更好,因为 gridstore 对象将是一个读/写流兼容对象:)
/**
* A simple example showing how to pipe a file stream through from gridfs to a file
*
* @_class gridstore
* @_function stream
* @ignore
*/
exports.shouldCorrectlyPipeAGridFsToAfile = function(test) {
var db = new Db('integration_tests', new Server("127.0.0.1", 27017,
{auto_reconnect: false, poolSize: 1, ssl:useSSL}), {native_parser: native_parser});
// Establish connection to db
db.open(function(err, db) {
// Open a file for writing
var gridStoreWrite = new GridStore(db, "test_gs_read_stream_pipe", "w", {chunkSize:1024});
gridStoreWrite.writeFile("./test/gridstore/test_gs_weird_bug.png", function(err, result) {
// Open the gridStore for reading and pipe to a file
var gridStore = new GridStore(db, "test_gs_read_stream_pipe", "r");
gridStore.open(function(err, gridStore) {
// Grab the read stream
var stream = gridStore.stream(true);
// When the stream is finished close the database
stream.on("end", function(err) {
// Read the original content
var originalData = fs.readFileSync("./test/gridstore/test_gs_weird_bug.png");
// Ensure we are doing writing before attempting to open the file
fs.readFile("./test_gs_weird_bug_streamed.tmp", function(err, streamedData) {
// Compare the data
test.deepEqual(originalData, streamedData);
// Close the database
db.close();
test.done();
});
})
// Create a file write stream
var fileStream = fs.createWriteStream("./test_gs_weird_bug_streamed.tmp");
// Pipe out the data
stream.pipe(fileStream);
})
})
});
}
关于Node.js 显示来自 Mongo 的 GridFS 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10588872/
如何通过 mongo shell 将文件“上传”到我的 MongoDB 以及如何检索同一文件?我想知道,这样做之后的输出是什么。 我认为展示我所做的将表明我的尝试是多么愚蠢。 db.fs.files.
我找到了 this benchmark但它很旧(2010)。 有没有人使用以下方法进行基准测试: 使用 Nginx-GridFS 提供图片 VS 图片来自Tornado 最佳答案 我们一直在使用我们的
我通过代码片段将文件写入gridfs,但我无法找到将字符串更新到Gridfs的写入方法。 下面的代码片段将使用路径进行更新,但是直接字符串缓冲区怎么样? var metadata = { "p
我想更新 GrifFs 文件集合中元数据的单个字段。 我阅读了有关 Spring Data MongoDB 的文档,但没有找到任何 API。 到目前为止,我找到的唯一解决方案是直接使用 Mongo A
使用gridfs-stream,查找和抓取文件时如何指定bucket名称? 我的问题是在 stackoverflow 上发现的以下问题的后续问题 How can I specify a GridFS
我正在开发 NodeJs API,我选择使用 GridFS 来存储和下载文件。对于这个问题,我有两个 API:上传和下载。当我使用 Postman 调用它们时,这两个 API 都工作得很好;但是我在使
我正在尝试在我的 node.js 应用程序中设置文件 API。我的目标是能够将文件流直接写入 gridfs,而无需最初将文件存储到磁盘。看来我的创建代码正在运行。我能够将文件上传保存到gridfs。问
我正在使用最新版本的express、mongodb、nodejs等。我没有使用主体解析中间件,因为我上传文件时不想将文件存储在磁盘上。我只想将它们直接流式传输到 GridFs 中。我正在使用 grid
在将元数据信息实际存储到 mongoDB 之前,我正在努力将其附加到 dfile。我正在使用: const express = require("express"); const router = e
如何将 1.000.000 个带有 css、js、img 文件的网页保存到 mongodb+gridfs 中?如何定义页面和html文件之间的链接? 最佳答案 一般的sql->mongodb看这里:
GridFS 是 MongoDB 的一种规范,用于存储和检索大型文件,如图像、音频、视频等。GridFS 也是一种存储文件的文件系统,但其数据是存储在 MongoDB 集合中的,GridFS 甚至可以
通常我通过从 MongoDb 加载数据来创建 XLSX 二进制对象。然后通过 http 响应将其传输到客户端。这是我使用的代码,效果非常好。 服务器端代码: //Row data (rows) gen
我是NoSQL的新手,我正在使用MongoDB作为支持数据库,在Grails框架中开发零件和 Material 数据库。我正在尝试自动进行项目的初始批量导入,并且我正在寻找一些有关从何开始的想法。 我
我在应用程序中添加了一个步骤,通过 GridFS 保存文件,并添加了一个名为“已处理”的元数据字段,作为计划任务的标志,该任务检索新文件并将其发送以进行处理。由于 GridFS 的 Java 驱动程序
我正在使用一个遗留应用程序,该应用程序的数据模型中给定的 MongoDB 文档的大小有时可能会超过 16MB。这当然会在 Mongo 中触发异常,因此我们决定将一些集合转移到没有此大小限制的 Grid
给定一个输入流、一个文件名字符串和一个路径字符串,我如何使用 Java 将文件存储在 GridFS 中?现在我在没有路径的情况下保存了它: public ObjectId saveFile(Input
考虑“餐厅”mongodb 数据库中的以下“餐厅”集合文档。 { "_id" : ObjectId("55f6564073fc0a09338cf434"), "address" : { "bu
我正在做一些测试,看看我们是否可以在 MongoDB 上使用 GridFS 来存储文件以供将来的应用程序使用;我正在使用 10gen 的 C# 驱动程序将一个 80Mb 的文件“上传”到数据库。 第一
在使用 mongo gem 的 ruby 中,我找不到任何关于如何使用 GridFs 查找文件名的文档。 最佳答案 第一个get a connection to the database ,我们称
我正在使用 node.js 和 mongodb 开发类似 facebook 的应用程序。我已经能够成功地将图像文件上传到 GridFS 并使用 node-mongodb-native 驱动程序 wik
我是一名优秀的程序员,十分优秀!