Tools for representing files stored in GridFS.
Write a file to GridFS
Application developers should generally not need to instantiate this class directly - instead see the methods provided by GridFS.
Raises TypeError if root_collection is not an instance of Collection.
Any of the file level options specified in the GridFS Spec may be passed as keyword arguments. Any additional keyword arguments will be set as additional fields on the file document. Valid keyword arguments include:
- "_id": unique ID for this file (default: ObjectId) - this "_id" must not have already been used for another file
- "filename": human name for the file
- "contentType" or "content_type": valid mime-type for the file
- "chunkSize" or "chunk_size": size of each of the chunks, in bytes (default: 256 kb)
- "encoding": encoding used for this file. In Python 2, any unicode that is written to the file will be converted to a str. In Python 3, any str that is written to the file will be converted to bytes.
Parameters : |
|
---|
The '_id' value for this file.
This attribute is read-only.
Chunk size for this file.
This attribute is read-only.
Flush the file and close it.
A closed file cannot be written any more. Calling close() more than once is allowed.
Is this file closed?
Mime-type for this file.
Name of this file.
Length (in bytes) of this file.
This attribute is read-only and can only be read after close() has been called.
MD5 of the contents of this file (generated on the server).
This attribute is read-only and can only be read after close() has been called.
Date that this file was uploaded.
This attribute is read-only and can only be read after close() has been called.
Write data to the file. There is no return value.
data can be either a string of bytes or a file-like object (implementing read()). If the file has an encoding attribute, data can also be a unicode (str in python 3) instance, which will be encoded as encoding before being written.
Due to buffering, the data may not actually be written to the database until the close() method is called. Raises ValueError if this file is already closed. Raises TypeError if data is not an instance of str (bytes in python 3), a file-like object, or an instance of unicode (str in python 3). Unicode data is only allowed if the file has an encoding attribute.
Parameters : |
|
---|
New in version 1.9: The ability to write unicode, if the file has an encoding attribute.
Write a sequence of strings to the file.
Does not add seperators.
Read a file from GridFS
Application developers should generally not need to instantiate this class directly - instead see the methods provided by GridFS.
Either file_id or file_document must be specified, file_document will be given priority if present. Raises TypeError if root_collection is not an instance of Collection.
Parameters : |
|
---|
New in version 1.9: The file_document parameter.
The '_id' value for this file.
This attribute is read-only.
Return an iterator over all of this file’s data.
The iterator will return chunk-sized instances of str (bytes in python 3). This can be useful when serving files using a webserver that handles such an iterator efficiently.
List of aliases for this file.
This attribute is read-only.
Chunk size for this file.
This attribute is read-only.
Make GridOut more generically file-like.
Mime-type for this file.
This attribute is read-only.
Length (in bytes) of this file.
This attribute is read-only.
MD5 of the contents of this file (generated on the server).
This attribute is read-only.
Metadata attached to this file.
This attribute is read-only.
Name of this file.
This attribute is read-only.
Read at most size bytes from the file (less if there isn’t enough data).
The bytes are returned as an instance of str (bytes in python 3). If size is negative or omitted all data is read.
Parameters : |
|
---|
Read one line or up to size bytes from the file.
Parameters : |
|
---|
New in version 1.9.
Set the current position of this file.
Parameters : |
|
---|
Return the current position of this file.
Date that this file was first uploaded.
This attribute is read-only.
No longer supported.
Changed in version 1.6: The GridFile class is no longer supported.