Skip to content

Instantly share code, notes, and snippets.

@omarsar
Created August 12, 2018 23:21
Show Gist options
  • Save omarsar/a7e28db93f6557ebba58a92a1e1d8539 to your computer and use it in GitHub Desktop.
Save omarsar/a7e28db93f6557ebba58a92a1e1d8539 to your computer and use it in GitHub Desktop.
def read_file(file_id):
"""
Download file from Google Drive
Argument: file_id
Returns: downloaded file
"""
file_id = file_id
import io
from googleapiclient.http import MediaIoBaseDownload
request = drive_service.files().get_media(fileId=file_id)
downloaded = io.BytesIO()
downloader = MediaIoBaseDownload(downloaded, request)
done = False
while done is False:
# _ is a placeholder for a progress object that we ignore.
# (Our file is small, so we skip reporting progress.)
_, done = downloader.next_chunk()
downloaded.seek(0)
return downloaded
#print 'Downloaded file contents are:', downloaded.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment