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"
29typedef unsigned long long gridfs_offset;
42 _data[
"data"].binDataClean(len);
46 const char* data(
int& len)
const {
47 return _data[
"data"].binDataClean(len);
75 unsigned int getChunkSize()
const;
87 const std::string& remoteName =
"",
88 const std::string& contentType =
"");
101 const std::string& remoteName,
102 const std::string& contentType =
"");
124 std::auto_ptr<DBClientCursor>
list()
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;
215 void _exists()
const;
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();
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:1422
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:226
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:156
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:162
Object ID type.
Definition oid.h:60
Represents a Mongo query expression.
Definition dbclientinterface.h:403
Core MongoDB C++ driver interfaces are defined here.
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20