gridfs

create own files_id in mongo GridFs using PHP

限于喜欢 提交于 2019-12-11 08:26:38
问题 for a better distribution of files in a sharded Mongo GridFs I'd like to create my own files_id. How this can be done in Java is described here: http://groups.google.com/group/mongodb-user/msg/524bae1602770587 But how to do this in PHP? I could find no hint in the API documentation, I use storeBytes for saving the files: http://www.php.net/manual/en/mongogridfs.storebytes.php 回答1: You should be able to just set this in the "$extra" argument with the "_id" key, something like: $m = new Mongo;

What data 'structure' does fs.get_last_version return?

一笑奈何 提交于 2019-12-11 05:08:05
问题 When I use get_last_version to get an image from the database, what is actually returned ie an array, the merged binary data of all the chunks that make up the file (as a string), or something else? dbname = 'grid_files' db = connection[dbname] fs = gridfs.GridFS(db) filename = "my_image.jpg" my_image_file = fs.get_last_version(filename=filename) I'm wanting to base64 encode my_image_file with: import base64 encoded_img_file = base64.b64encode(my_image_file) return encoded_img_file But I'm

Carrierwave + Mongoid + gridfs + Padrino admin image upload

爷,独闯天下 提交于 2019-12-11 02:49:44
问题 i'm trying to get carrierwave + mongoid + gridfs to work for uploading images via padrino admin and then showing on front-end. at a loss as to glue everything. can someone help? following https://blog.engineyard.com/2011/a-gentle-introduction-to-carrierwave/ and https://github.com/carrierwaveuploader/carrierwave-mongoid. trying to persist an "Artwork" with an image upload returns: NoMethodError at /admin/artworks/update/53a0eedcf2c7961066000002 undefined method ` bson_dump ' for # file: hash

Why gridfs get isn't working on file id (ObjectId) only by filename

时光毁灭记忆、已成空白 提交于 2019-12-10 17:09:22
问题 I'm using nodejs mongodb mongoose and gridfs. when I try to get a file by it's filname everthing is working great by if i want to get it by id i get Error: The file you wish to read does not exist. I the following code the console.log("res.pic_id : " + res.pic_id) i get the correct ObjectId. Here's the code : var GridFS = require('GridFS').GridFS; var myFS = new GridFS('db'); var fs = require('fs') var Profile = db.model('Profile'); Profile.findOne({'_id' : clientID},['_id', 'username','pic

Using Gridfs under Laravel 5.3 with mongo-php-library 2.2 driver

你说的曾经没有我的故事 提交于 2019-12-10 16:28:29
问题 We use PHP7, latest MongoDB PECL package (1.2.2) - Laravel 5.3 - jenssegers/laravel-mongodb 3.1 I want to use GridFS. It's normally available into the MongoDB PECL package but there are no documentation nor working code example. 回答1: You can use Bucket class for upload and download documents to mongodb grid on mongo-php-library 2.2 driver. //upload file $bucket = \DB::connection('mongodb')->getMongoDB()->selectGridFSBucket(); $resource = fopen($file_path, "a+"); $file_id = $bucket-

Cleaning orphaned files out of GridFS

牧云@^-^@ 提交于 2019-12-10 09:54:27
问题 I have a collection referencing GridFS files, generally 1-2 files per record. The collections are reasonably large - about 705k records in the parent collection, and 790k GridFS files. Over time, there have become a number of orphaned GridFS files - the parent records were deleted, but the referenced files weren't. I'm now attempting to clean the orphaned files out of the GridFS collection. The problem with an approach like suggested here is that combining the 700k records into a single large

PHP操作MongoDB GridFS 存储文件,如图片文件

 ̄綄美尐妖づ 提交于 2019-12-10 05:12:15
GridFS是MongoDB的一个内置功能,它提供一组文件操作的API以利用MongoDB存储文件,GridFS的基本原理是将文件保存在两个Collection中,一个保存文件索引,一个保存文件内容,文件内容按一定大小分成若干块,每一块存在一个Document中,这种方法不仅提供了文件存储,还提供了对文件相关的一些附加属性(比如MD5值,文件名等等)的存储。 01 <?php 02 // 初始化gridfs 03 $conn = new Mongo(); // 连接MongoDB 04 $db = $conn->photos; // 选择数据库 05 $collection = $db->getGridFS(); // 取得gridfs对象 06 07 // gridfs有三种方式存储文件 08 // 第一种直接存储文件 09 $id = $collection->storeFile("./logo.png"); 10 11 // 第二种存储文件二进制流 12 $data = get_file_contents("./logo.png"); 13 $id = $collection->storeBytes($data,array("param" => '附加参数将随图片一起存入')); 14 15 // 第三种保存直接表单提交的文件$_FILES 16 $id =

Node.js displaying images from Mongo's GridFS

我的未来我决定 提交于 2019-12-09 01:38:12
问题 I have a nodejs app that uses Mongo and GridFS to store images. I'm trying to display these images to the browser via Node.js (using express framework). I'm currently using: res.writeHead(200, {'Content-Type': 'image/jpeg' }); res.end(imageStore.currentChunk.data.buffer, 'binary'); imageStore is a the gridStore object after creating a new GridStore and calling gridStore.open(...) var gridStore = new GridStore(self.collection.db, doc._id, doc.filename, 'r', { chunk_size: doc.chunkSize });

Reading and Displaying images from mongoDB using GridFs

*爱你&永不变心* 提交于 2019-12-09 01:35:00
问题 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 });

stream audio/video files from gridFS on the browser

五迷三道 提交于 2019-12-08 19:54:25
I have been trying to read an audio file from mongoDB which i have stored using GridFS. I could download the file in the system and play from it but I wanted to stream those audio/video files from the DB itself and play it in the browser. Is there anyway to do that without downloading the file to the system? Any help would be good. The PHP GridFS support has a MongoGridFSFile::getResource() function that allows you to get the stream as a resource - which doesn't load the whole file in memory. Combined with fread/echo or stream_copy_to_stream you can prevent the whole file from being loaded in