GridFS Example

    See also

    The API docs for gridfs.

    See also

    We start by creating a instance to use:

    Every GridFS instance is created with and will operate on a specific instance.

    Saving and Retrieving Data

    The simplest way to work with is to use its key/value interface (the put() and methods). To write data to GridFS, use put():

    returns a file-like object, so we get the file’s contents by calling read().

    In addition to putting a as a GridFS file, we can also put any file-like object (an object with a method). GridFS will handle reading the file in chunk-sized segments automatically. We can also add additional attributes to the file as keyword arguments:

    The attributes we set in put() are stored in the file document, and retrievable after calling . Some attributes (like ) are special and are defined in the GridFS specification - see that document for more details.