gridfs

Reading and Displaying images from mongoDB using GridFs

耗尽温柔 提交于 2019-11-30 23:27:17
I have been able to successfully upload images to mongoDB using GridFs. Below are images from my database: fs.files: fs.chunks: Below is the code I used to upload images: var Grid = require('gridfs-stream'); var mongoose = require("mongoose"); Grid.mongo = mongoose.mongo; var gfs = new Grid(mongoose.connection.db); app.post('/picture', function(req, res) { var part = req.files.filefield; var writeStream = gfs.createWriteStream({ filename: part.name, mode: 'w', content_type:part.mimetype }); writeStream.on('close', function() { return res.status(200).send({ message: 'Success' }); });

电子商务文件存储及读取服务的设计和开发思路(JMagick用于生成高清的缩略图)

女生的网名这么多〃 提交于 2019-11-30 21:11:49
商品图片,平均200-500K,说大不大,说小不小,但量大且细碎,通常通过页面上传,全部保存在文件里,管理和索引都很慢,几乎无法备份,读取也很慢。 传统的基于磁盘存储的缺陷: 1、 图片存储和应用程序在一个服务器上,图片的读取占用大量的磁盘IO,在访问量高的时候,图片读取和应用程序相互影响。特别互联网环境下的文件多以几K,几十K的小文件为主,磁盘寻址和读取,缓存命中率都比较低。 2、 当规模大到一定程度,应用服务器将扩展到多服务器集群环境中,传统的磁盘存储在集群环境下面临集中存储的挑战。 3、 基于磁盘的存储,在面临未来扩容的情况下,也显的能力不足,通过增加磁盘的容量很快将达到极限,最好的方法还是多服务器集群的存储。所以在存储和读取上的难度将陡然增加。 所以鉴于此,放弃简单的磁盘存储,而且各大互联网公司都有自己的文件系统,google的GFS,淘宝的TFS,其他中小型的网站,会采用类似于mogileFS这样开源的文件系统。所以利用开源的文件系统来搭建我们自己的文件系统、文件服务器以及文件的存取服务。 在众多开源的文件系统中,我们选用MongoDB的GridFS作为文件存储服务。 MongoDB特性 MongoDB是一个可扩展、高性能的下一代数据库,由C++语言编写,旨在为web应用提供可扩展的高性能数据存储解决方案。它的特点是高性能、易部署、易使用,存储数据非常方便,主要特性有:

Query on MongoDB GridFS metadata (Java)

你说的曾经没有我的故事 提交于 2019-11-30 12:46:56
What I'm trying to do is fetching a list of GridFS files by querying an field of the metadata. For example I got a GridFS file document looking like: { "_id" : { "$oid" : "4f95475f5ef4fb269dbac954"} , "chunkSize" : 262144 , "length" : 3077 , "md5" : "f24ea7ac05c5032f08808c6faabf413b" , "filename" : "file_xyz.txt" , "contentType" : null , "uploadDate" : { "$date" : "2012-04-23T12:13:19.606Z"} , "aliases" : null , "metadata" : { "target_field" : "abcdefg"}} And I want to query all files containing "target_field" = "abcdefg". I created my query as follows: BasicDBObject query = new BasicDBObject(

Meteor collectionfs insert server side

不羁岁月 提交于 2019-11-30 07:42:40
hi everyone i using collectionfs + gridfs + cfs filesystem, on collectionfs documentation i find how to insert file on client side like this : Template.myForm.events({ 'change .myFileInput': function(event, template) { FS.Utility.eachFile(event, function(file) { Images.insert(file, function (err, fileObj) { //Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP }); }); } }); on that case will insert file on client side, but in my case i remove insecure, so can't do insert on client side, i try to make it on server side . so this is my code : Template.myForm.events({

How to perform Update operations in GridFS (using Java)?

半世苍凉 提交于 2019-11-30 06:01:30
问题 I am using Mongo-Java-Driver 2.13 I stored a PDF file ( size 30mb ) in GridFS . I am able to perform insertion, deletion and find operation easily. MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("testDB"); File pdfFile = new File("/home/dev/abc.pdf"); GridFS gfs = new GridFS(db,"books"); GridFSInputFile inputFile = gfs.createFile(pdfFile); inputFile.setId("101"); inputFile.put("title", "abc"); inputFile.put("author", "xyz"); inputFile.save(); data is persisted in

How to use GridFS to store images using Node.js and Mongoose

你说的曾经没有我的故事 提交于 2019-11-30 03:46:20
I am new to Node.js. Can anyone provide me an example of how to use GridFS for storing and retrieving binary data, such as images, using Node.js and Mongoose? Do I need to directly access GridFS? I was not satisfied with the highest rated answer here and so I'm providing a new one: I ended up using the node module 'gridfs-stream' (great documentation there!) which can be installed via npm. With it, and in combination with mongoose, it could look like this: var fs = require('fs'); var mongoose = require("mongoose"); var Grid = require('gridfs-stream'); var GridFS = Grid(mongoose.connection.db,

Append data to existing gridfs file

邮差的信 提交于 2019-11-29 11:37:37
As i can see java mongo driver does not provide capability to get OutputStream from existing gridFS file com.mongodb.gridfs.GridFSFile I have to create GridFSInputFile directly or use gridFs.createFile() method. Is it a lack of java driver or a restriction of gridfs ? Could you suggest any workaround except create new file/delete old one ? Thank you pingw33n GridFS is not a core feature of MongoDB but a convention of storing binary data with accompanying metadata. You should be able to modify any document in fs.chunks collection in a usual manner while keeping corresponding document in fs

Meteor collectionfs insert server side

痴心易碎 提交于 2019-11-29 10:27:53
问题 hi everyone i using collectionfs + gridfs + cfs filesystem, on collectionfs documentation i find how to insert file on client side like this : Template.myForm.events({ 'change .myFileInput': function(event, template) { FS.Utility.eachFile(event, function(file) { Images.insert(file, function (err, fileObj) { //Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP }); }); } }); on that case will insert file on client side, but in my case i remove insecure, so can't do

mongoDB 之 GridFS简介(一)

笑着哭i 提交于 2019-11-29 07:32:09
前言 :GridFS从名字来看,就明白是一个文件系统,它是mongodb的一个子模块,使用GridFS可以基于mongodb来持久存储文件.并且支持分布式应用(文件分布存储和读取). 使用场景:如果你的系统有如下情景 1) 有大量的上传图片(用户上传或者系统本身的文件发布等) 2) 文件的量级处于飞速增长,有可能打到单机操作系统自己的文件系统的查询性能瓶颈,甚至超过单机硬盘的扩容范围. 3) 文件的备份(不适用gridfs这种三方也可以做,但是不尽方便),文件系统访问的故障转移和修复.. 4) 文件的索引,存储除文件本身以外还需要关联更多的元数据信息(比如,不仅仅存储文件,还要保存一些文件的发布式作者/发布时间/文件tag属性等等自定义信息)并且需要索引的... 5) 基于4),对文件的分类模糊,如果采用操作系统的文件系统,文件夹分类关系混乱或者无法分类时.. 6) 当前系统是基于web的,对图片的访问根据url了规则路由的..(普通文件系统也可以) 7) 文件尺寸较小,而且众多,且文件有可能被迁移/删除等.. GridFS和其他分布式文件系统相比,并没有什么特殊的地方....如果有,那就是它和mongodb有一腿... GridFS是mongodb中用户存储大对象的工具,对于mongodb,BSON格式的数据(文档)存储有尺寸限制,最大为16M.但是在实际系统开发中

mongodb Gridfs操作

牧云@^-^@ 提交于 2019-11-29 07:31:54
mongodb Gridfs操作 GridFS 介绍 GridFS是MongoDB规范用于存储和检索大文件,如图片,音频文件,视频文件等。这是一种文件系统用来存储文件,但数据存储于MongoDB集合中。GridFS存储文件比其文档大小16MB限制的更大能力。 GridFS的划分一个文件分成块存储数据每个块在一个单独的文件,每个最大尺寸255K。 GridFS默认使用两个集合 fs.files 和 fs.chunks 存储该文件的元数据和块。每组块标识其唯一的_id ObjectID字段。fs.files切断作为父文件。 fs.chunks 文档 files_id 字段链接块到其父文件。 以下是fs.files集合的样本文件: { "filename": "test.txt", "chunkSize": NumberInt(261120), "uploadDate": ISODate("2014-04-13T11:32:33.557Z"), "md5": "7b762939321e146569b07f72c62cca4f", "length": NumberInt(646) } 文件指定的文件名,块大小,上传日期,和长度。 以下是 fs.chunks 文件的样本文件: { "files_id": ObjectId("534a75d19f54bfec8a2fe44b"), "n":