20#include "boost/scoped_array.hpp"
22#include "mongo/bson/bsonelement.h"
23#include "mongo/bson/bsonobj.h"
25#include "mongo/client/export_macros.h"
29 typedef unsigned long long gridfs_offset;
33 class GridFileBuilder;
42 _data[
"data"].binDataClean( len );
46 const char * data(
int & len )
const {
47 return _data[
"data"].binDataClean( len );
75 unsigned int getChunkSize()
const;
86 BSONObj storeFile(
const std::string& fileName ,
const std::string& remoteName=
"" ,
const std::string& contentType=
"");
97 BSONObj storeFile(
const char* data ,
size_t length ,
const std::string& remoteName ,
const std::string& contentType=
"");
119 std::auto_ptr<DBClientCursor>
list()
const;
130 std::string _filesNS;
131 std::string _chunksNS;
132 unsigned int _chunkSize;
135 BSONObj insertFile(
const std::string& name,
const OID&
id, gridfs_offset length,
const std::string& contentType);
155 return ! _obj.isEmpty();
158 std::string getFilename()
const {
159 return _obj[
"filename"].str();
162 int getChunkSize()
const {
163 return (
int)(_obj[
"chunkSize"].number());
166 gridfs_offset getContentLength()
const {
167 return (gridfs_offset)(_obj[
"length"].number());
170 std::string getContentType()
const {
171 return _obj[
"contentType"].valuestr();
174 Date_t getUploadDate()
const {
175 return _obj[
"uploadDate"].date();
178 std::string getMD5()
const {
179 return _obj[
"md5"].str();
182 BSONElement getFileField(
const std::string& name )
const {
186 BSONObj getMetadata()
const;
188 int getNumChunks()
const {
189 return (
int) ceil( (
double)getContentLength() / (
double)getChunkSize() );
192 GridFSChunk getChunk(
int n )
const;
197 gridfs_offset
write( std::ostream & out )
const;
202 gridfs_offset
write(
const std::string& where )
const;
207 void _exists()
const;
245 const std::string& contentType=
"" );
249 const size_t _chunkSize;
250 unsigned int _currentChunk;
253 boost::scoped_array<char> _pendingData;
254 size_t _pendingDataSize;
255 gridfs_offset _fileLength;
257 const char* _appendChunk(
const char* data,
size_t length,
258 bool forcePendingInsert );
260 void _appendPendingData();
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
abstract class that implements the core db operations
Definition dbclientinterface.h:1329
GridFS is for storing large file-style objects in MongoDB.
Definition gridfs.h:60
BSONObj storeFile(const std::string &fileName, const std::string &remoteName="", const std::string &contentType="")
puts the file reference by fileName into the db
GridFS(DBClientBase &client, const std::string &dbName, const std::string &prefix="fs")
GridFile findFile(Query query) const
returns a file object matching the query
GridFile findFileByName(const std::string &fileName) const
equiv to findFile( { filename : filename } )
void setChunkSize(unsigned int size)
std::auto_ptr< DBClientCursor > list() const
convenience method to get all the files
void removeFile(const std::string &fileName)
removes file referenced by fileName from the db
BSONObj storeFile(const char *data, size_t length, const std::string &remoteName, const std::string &contentType="")
puts the file represented by data into the db
std::auto_ptr< DBClientCursor > list(BSONObj query) const
convenience method to get all the files with a filter
class which allow to build GridFiles in a stream fashion way
Definition gridfs.h:218
void appendChunk(const char *data, size_t length)
Appends a chunk of data.
GridFileBuilder(GridFS *const grid)
mongo::BSONObj buildFile(const std::string &remoteName, const std::string &contentType="")
Inserts the description of the file in GridFS collection.
wrapper for a file stored in the Mongo database
Definition gridfs.h:148
gridfs_offset write(const std::string &where) const
write the file to this filename
gridfs_offset write(std::ostream &out) const
write the file to the output stream
bool exists() const
Definition gridfs.h:154
Object ID type.
Definition oid.h:60
Represents a Mongo query expression.
Definition dbclientinterface.h:387
Core MongoDB C++ driver interfaces are defined here.
the main MongoDB namespace
Definition bulk_operation_builder.h:24