Google Drive Python API; upload a media object which is NOT a file

Answering my own question

What I wanted to do was to get a file from a url and upload to drive.

Used MediaIoBaseUpload class instead of MediaUpload class.

response = urllib2.urlopen(url)
fh = BytesIO(response.read())
media_body = MediaIoBaseUpload(fh, mimetype='image/jpeg',
              chunksize=1024*1024, resumable=True)
body = {
        'title': 'pic.jpg'
    }
drive_service.files().insert(body=body, media_body=media_body).execute()

Tags:

Python

Drive