rubygoogle-drive-apigoogle-drive-shared-drivegoogle-api-ruby-client

How to upload a file to a shared drive with Google API Drive v3 ruby gem


I am trying to upload a file to a shared drive, however; if I set my drive_id in the options parameters, it still used my default drive, which is "My Drive".

What am I doing wrong? (The drive_id is just an example)

google_file = Google::Apis::DriveV3::File.new(drive_id: "123456789", name: 'test.txt')
drive = Google::Apis::DriveV3::DriveService.new
source_file Tempfile.new("text.txt")
drive.create_file(google_file, upload_source: file)

I have also tried setting the parent_ids when I create a file and am getting an error as well. See below:

Google::Apis::DriveV3::File.new(drive_id: '123456789', name: 'test.txt', parents: ['123456789'])

results in:
Google::Apis::ClientError: notFound: File not found: 123456789.

Any help here will be greatly appreciated!


Solution

  • I believe your goal is as follows.

    In this case, how about the following modification?

    Modified script:

    google_file = Google::Apis::DriveV3::File.new(name: 'test.txt', parents: ['###'])
    drive = Google::Apis::DriveV3::DriveService.new
    drive.create_file(google_file, upload_source: "text.txt", supports_team_drives: true)
    

    Note:

    References: