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,
87 const std::string& remoteName =
"",
88 const std::string& contentType =
"");
99 BSONObj storeFile(
const char* data,
101 const std::string& remoteName,
102 const std::string& contentType =
"");
109 void removeFile(
const std::string& fileName);
119 GridFile findFileByName(
const std::string& fileName)
const;
124 std::auto_ptr<DBClientCursor> list()
const;
129 std::auto_ptr<DBClientCursor> list(
BSONObj query)
const;
135 std::string _filesNS;
136 std::string _chunksNS;
137 unsigned int _chunkSize;
140 BSONObj insertFile(
const std::string& name,
142 gridfs_offset length,
143 const std::string& contentType);
163 return !_obj.isEmpty();
166 std::string getFilename()
const {
167 return _obj[
"filename"].str();
170 int getChunkSize()
const {
171 return (
int)(_obj[
"chunkSize"].number());
174 gridfs_offset getContentLength()
const {
175 return (gridfs_offset)(_obj[
"length"].number());
178 std::string getContentType()
const {
179 return _obj[
"contentType"].valuestr();
182 Date_t getUploadDate()
const {
183 return _obj[
"uploadDate"].date();
186 std::string getMD5()
const {
187 return _obj[
"md5"].str();
190 BSONElement getFileField(
const std::string& name)
const {
194 BSONObj getMetadata()
const;
196 int getNumChunks()
const {
197 return (
int)ceil((
double)getContentLength() / (
double)getChunkSize());
200 GridFSChunk getChunk(
int n)
const;
205 gridfs_offset write(std::ostream& out)
const;
210 gridfs_offset write(
const std::string& where)
const;
213 GridFile(
const GridFS* grid, BSONObj obj);
215 void _exists()
const;
241 void appendChunk(
const char* data,
size_t length);
252 mongo::BSONObj buildFile(
const std::string& remoteName,
const std::string& contentType =
"");
256 const size_t _chunkSize;
257 unsigned int _currentChunk;
260 boost::scoped_array<char> _pendingData;
261 size_t _pendingDataSize;
262 gridfs_offset _fileLength;
264 const char* _appendChunk(
const char* data,
size_t length,
bool forcePendingInsert);
266 void _appendPendingData();
GridFS is for storing large file-style objects in MongoDB.
Definition: gridfs.h:60
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
Object ID type.
Definition: oid.h:60
bool exists() const
Definition: gridfs.h:162
Core MongoDB C++ driver interfaces are defined here.
class which allow to build GridFiles in a stream fashion way
Definition: gridfs.h:226
wrapper for a file stored in the Mongo database
Definition: gridfs.h:156
Represents a Mongo query expression.
Definition: dbclientinterface.h:403
abstract class that implements the core db operations
Definition: dbclientinterface.h:1422
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78