0

I'd like to periodically download and upload a file from a shared teams drive on google drive. I can upload to the folder, but not download.

This is what I've tried

team_drive_id = 'YYY'
file_to_download= 'ZZZ'
parent_folder_id = 'XXX'

f = drive.CreateFile({
        'id':file_to_download,
        'parents': [{
        'kind': 'drive#fileLink',
        'teamDriveId': team_folder_id,
        'id': parent_drive_id
    }]
})
f= drive.CreateFile({'id': file_to_download})
f.GetContentFile('test.csv', mimetype='text/csv')

But this is what I get:

ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/file_to_download?alt=json returned "File not found: file_to_download">

Any suggestions?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Alex
  • 169
  • 1
  • 1
  • 8

1 Answers1

0

Following the documentation that can be seen here

First you create the file:

f = drive.CreateFile({'id': file_to_download})

then you set the content on the file

f.SetContentString("whatever comes inside this file, it is a csv so you know what to expect to be here")

and to finish the upload you need to do

f.Upload()

after that, the file is properly created there, you can read it using the GetContentString method

H_DANILO
  • 321
  • 1
  • 9
  • 1
    This only works when you are creating and downloading the file in the same session. If I try to come back later on, it is unable to find the file, or if I create another CreateFile instance using the newly generated ID, it returns a 404 file not found. – Alex Nov 03 '19 at 22:22