0
我部署了mongodb gridfs以減少圖像渲染時間並減少apache請求。我需要一些關於大尺寸圖像的說明,我們如何在瀏覽器中顯示它?MongoDB GridFS說明
事實上,我採取單個圖像和大小超過40MB的存儲在mongodb網格中。它通過使用以下命令進行存儲。但我無法在瀏覽器中顯示瀏覽器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);
}
- 庫馬蘭
在第二種情況下,需要多長時間從MongoDB服務器讀取所有字節? – WiredPrairie 2013-02-22 11:57:51
程序2:在FireFox中:採用20Sec,但它不在Chrome瀏覽器中工作,只顯示空白頁面。 – Kumaran 2013-02-22 12:21:59
如果你只是在本地加載到Chrome瀏覽器(不是通過MongoDB?),Chrome可以顯示文件嗎?另外 - 你也可以發送「content-length」嗎? – WiredPrairie 2013-02-22 13:00:44