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 );
67 GridFS(
DBClientBase& client ,
const std::string& dbName ,
const std::string& prefix=
"fs" );
73 void setChunkSize(
unsigned int size);
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=
"");
104 void removeFile(
const std::string& fileName );
114 GridFile findFileByName(
const std::string& fileName )
const;
119 std::auto_ptr<DBClientCursor> list()
const;
124 std::auto_ptr<DBClientCursor> list(
BSONObj query )
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;
205 GridFile(
const GridFS * grid , BSONObj obj );
207 void _exists()
const;
209 const GridFS * _grid;
233 void appendChunk(
const char* data,
size_t length );
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();
GridFS is for storing large file-style objects in MongoDB.
Definition: gridfs.h:60
the main MongoDB namespace
Definition: bulk_operation_builder.h:24
Object ID type.
Definition: oid.h:60
bool exists() const
Definition: gridfs.h:154
Core MongoDB C++ driver interfaces are defined here.
class which allow to build GridFiles in a stream fashion way
Definition: gridfs.h:218
wrapper for a file stored in the Mongo database
Definition: gridfs.h:148
Represents a Mongo query expression.
Definition: dbclientinterface.h:387
abstract class that implements the core db operations
Definition: dbclientinterface.h:1330
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78