Open
Description
When using the MediaFileUpload class to upload files to Google Drive via google-api-python-client, the file remains open after the upload completes, resulting in a PermissionError when I attempt to delete the file.
Code example:
from googleapiclient.http import MediaFileUpload
file_metadata = {'name': "file.zip"}
media = MediaFileUpload('D:\\file.zip', mimetype='application/zip', resumable=True)
request = drive.files().create(body=file_metadata, media_body=media)
response = request.execute()
os.remove('D:\\file.zip') # Raises PermissionError
Expected behavior: The file should automatically close after uploading so that it can be deleted without errors.
Actual behavior: The file remains open, and attempting to delete it results in a PermissionError.
Solution: I resolved the issue manually by adding media._fd.close() after the upload completes to close the file.