0

我部署了 mongodb gridfs 以减少图像渲染时间并减少 apache 请求。我需要一些关于大尺寸图像的说明,我们如何在浏览器中显示它?

实际上,我拍摄了单个图像并且大小超过 40MB 以将其存储在 mongodb gridfs 中。它使用以下命令存储。但我无法在浏览器中显示它 40MB 图像在浏览器中,我们如何在浏览器中流式传输图像?. 请帮助我们。

命令:

步骤1:

./mongofiles -d myfiles put /home/bharat/bin/cron/"CT0072 Madagascar Cartoon Characters .jpg"
connected to: 127.0.0.1
added file: { _id: ObjectId('512606b93f15f684e8271aee'), filename: "/home/bharat/bin/cron/CT0072 Madagascar Cartoon Characters .jpg", chunkSize: 262144, uploadDate: new Date(1361446588575), md5: "ab3e9d6a6f01f87e28f76148824a6d4b", length: 20020718 }
done!

第2步:

./mongofiles -d myfiles list
connected to: 127.0.0.1
/home/bharat/bin/cron/CT0072 Madagascar Cartoon Characters .jpg 20020718

第 3 步:

./mongo
MongoDB shell version: 1.8.2
> show tables;
fs.chunks
fs.files
system.indexes
> db.fs.chunks.count();
77

第 4 步: 编写 PHP 文件

**Program 1** - Its showing image below 10MB file. But 40MB file is not showing in Chrome Browse but Firefox showing and taking more time to display.

$mongo = new Mongo("128.181.10.28:27017");
$db = $mongo->myfiles;
$gridFS = $db->getGridFS();
$image = $gridFS->findOne("/home/bharat/bin/cron/tomas-hurricane.jpg");
$filedata = $image->getBytes();
header("Content-Length: " . strlen($filedata));
header("Content-Type: image/jpeg");
ob_clean();
echo($filedata);

**Program 2** : Tried second program but not working.

Tried 2nd Program
$mongo = new Mongo("128.181.10.28:27017");
$db = $mongo->myfiles;
$gridFS = $db->getGridFS();
$image = $gridFS->findOne("/home/bharat/bin/cron/tomas-hurricane.jpg");
header("Content-Type: image/jpeg");
$stream = $image->getResource();
while (!feof($stream)) {
    echo fread($stream, 8192);
}
  • 库马兰
4

1 回答 1

0

首先,40 MB 对于浏览器来说确实很大,尤其是在您使用 IE 时。尝试较小的图像。

其次,正如我在这里指出的,您可以使用 MongoDB REST API,这是获取图像的好方法。

于 2013-03-12T19:00:26.753 回答