@@ -426,8 +426,7 @@ def open_upload_stream(self, filename, chunk_size_bytes=None,
426426 grid_in.write("data I want to store!")
427427 grid_in.close() # uploaded on close
428428
429- Returns an instance of :class:`~gridfs.grid_file.GridIn` and the _id
430- of the file to upload.
429+ Returns an instance of :class:`~gridfs.grid_file.GridIn`.
431430
432431 Raises :exc:`~gridfs.errors.NoFile` if no such version of
433432 that file exists.
@@ -449,8 +448,7 @@ def open_upload_stream(self, filename, chunk_size_bytes=None,
449448 if metadata is not None :
450449 opts ["metadata" ] = metadata
451450
452- gin = GridIn (self ._collection , ** opts )
453- return gin , gin ._id
451+ return GridIn (self ._collection , ** opts )
454452
455453 def upload_from_stream (self , filename , source , chunk_size_bytes = None ,
456454 metadata = None ):
@@ -484,14 +482,11 @@ def upload_from_stream(self, filename, source, chunk_size_bytes=None,
484482 files collection document. If not provided the metadata field will
485483 be omitted from the files collection document.
486484 """
487- gin , _id = self .open_upload_stream (filename , chunk_size_bytes ,
488- metadata )
489- try :
485+ with self .open_upload_stream (
486+ filename , chunk_size_bytes , metadata ) as gin :
490487 gin .write (source )
491- finally :
492- gin .close ()
493488
494- return _id
489+ return gin . _id
495490
496491 def open_download_stream (self , file_id ):
497492 """Opens a Stream from which the application can read the contents of
0 commit comments