Put data in GridFS as a new file. Equivalent to doing:: with fs.new_file(**kwargs) as f: f.write(data) `data` can be either an instance of :class:`bytes` or a file-like object providing a :meth:`read` method. If an `encoding` keyword argumen
(self, data: Any, **kwargs: Any)
| 127 | return GridIn(self._collection, **kwargs) |
| 128 | |
| 129 | def put(self, data: Any, **kwargs: Any) -> Any: |
| 130 | """Put data in GridFS as a new file. |
| 131 | |
| 132 | Equivalent to doing:: |
| 133 | |
| 134 | with fs.new_file(**kwargs) as f: |
| 135 | f.write(data) |
| 136 | |
| 137 | `data` can be either an instance of :class:`bytes` or a file-like |
| 138 | object providing a :meth:`read` method. If an `encoding` keyword |
| 139 | argument is passed, `data` can also be a :class:`str` instance, which |
| 140 | will be encoded as `encoding` before being written. Any keyword |
| 141 | arguments will be passed through to the created file - see |
| 142 | :meth:`~gridfs.grid_file.GridIn` for possible arguments. Returns the |
| 143 | ``"_id"`` of the created file. |
| 144 | |
| 145 | If the ``"_id"`` of the file is manually specified, it must |
| 146 | not already exist in GridFS. Otherwise |
| 147 | :class:`~gridfs.errors.FileExists` is raised. |
| 148 | |
| 149 | :param data: data to be written as a file. |
| 150 | :param kwargs: keyword arguments for file creation |
| 151 | |
| 152 | .. versionchanged:: 3.0 |
| 153 | w=0 writes to GridFS are now prohibited. |
| 154 | """ |
| 155 | with GridIn(self._collection, **kwargs) as grid_file: |
| 156 | grid_file.write(data) |
| 157 | return grid_file._id |
| 158 | |
| 159 | def get(self, file_id: Any, session: Optional[ClientSession] = None) -> GridOut: |
| 160 | """Get a file from GridFS by ``"_id"``. |