@@ -104,12 +104,17 @@ constructor, as shown below:
104
104
Upload Files
105
105
------------
106
106
107
- Use the ``open_upload_stream()`` method from the ``GridFSBucket`` class to create an upload
108
- stream for a given file name. The
109
- ``open_upload_stream()`` method allows you to specify configuration information
110
- such as file chunk size and other field/value pairs to store as metadata. Set
111
- these options as parameters of ``open_upload_stream()``, as shown in the
112
- following code example:
107
+ Use the ``upload_from_stream()`` method from the ``GridFSBucket`` class to upload
108
+ a file to a GridFS bucket. Pass the following parameters to the ``upload_from_stream()``
109
+ method:
110
+
111
+ - ``filename``: The name of the file to store the uploaded content
112
+ - ``source``: The file you want to upload
113
+ - ``chunk_size_bytes``: The number of bytes per chunk of this file (optional).
114
+ - ``metadata``: The file metadata (optional).
115
+
116
+ The following code example uploads a file located at ``./file_to_upload`` and stores
117
+ its contents in ``my_file``:
113
118
114
119
.. literalinclude:: /includes/gridfs/gridfs.py
115
120
:language: python
@@ -138,7 +143,7 @@ from which you can access the results. To learn more about ``Cursor`` objects in
138
143
{+driver-short+}, see :ref:`<pymongo-cursors>`.
139
144
140
145
The following code example shows you how to retrieve and print file metadata
141
- from all your files in a GridFS bucket. It uses the ``for...of `` syntax to traverse the
146
+ from all your files in a GridFS bucket. It uses the ``for...in `` syntax to traverse the
142
147
``Cursor`` iterable and display the results:
143
148
144
149
.. literalinclude:: /includes/gridfs/gridfs.py
@@ -158,12 +163,11 @@ Download Files
158
163
--------------
159
164
160
165
You can download files from your MongoDB database by using the
161
- ``open_download_stream_by_name ()`` method from ``GridFSBucket`` to create a
162
- download stream .
166
+ ``download_to_stream_by_name ()`` method from the ``GridFSBucket``
167
+ class .
163
168
164
169
The following example shows you how to download a file referenced
165
- by the file name, stored in the ``filename`` field, into your working
166
- directory:
170
+ by the file name, ``my_file``, into a file named ``output_file``:
167
171
168
172
.. literalinclude:: /includes/gridfs/gridfs.py
169
173
:language: python
@@ -177,7 +181,7 @@ directory:
177
181
GridFS will stream the most recent file with the given name (as
178
182
determined by the ``uploadDate`` field).
179
183
180
- Alternatively, you can use the ``open_download_stream ()``
184
+ Alternatively, you can use the ``download_to_stream ()``
181
185
method, which takes the ``_id`` field of a file as a parameter:
182
186
183
187
.. literalinclude:: /includes/gridfs/gridfs.py
@@ -204,7 +208,7 @@ bucket. You must specify the file to rename by its ``_id`` field
204
208
rather than its file name.
205
209
206
210
The following example shows how to update the ``filename`` field to
207
- ``"newFileName "`` by referencing a document's ``_id`` field:
211
+ ``"new_file_name "`` by referencing a document's ``_id`` field:
208
212
209
213
.. literalinclude:: /includes/gridfs/gridfs.py
210
214
:language: python
0 commit comments