ahhmarr
ahhmarr

Reputation: 2320

Specify folder name while upload file via Google Drive API

Here is my code snippet:

    $service=new Google_Service_Drive($client);
    $file=new Google_Service_Drive_DriveFile();
    $file->setTitle($title);
    $file->setDescription('some desciption');
    $file->setMimeType($mimeType);
    $createdFile=$service->files->insert($file,[
        'data'          => $data,
        'mimeType'      => $mimeType,
        'uploadType'    => 'media'
        ]);

This uploads the file to the root of the google drive.

I want to change the upload location to another folder, how can I achieve this?

Upvotes: 1

Views: 1318

Answers (1)

ahhmarr
ahhmarr

Reputation: 2320

never mind i found it myself it seems that you need to instantiate a parent reference service and pass it to the parents method of your DriveFIle

$parent = new Google_Service_Drive_ParentReference(); 
$parent->setId('folderid');
$file->setParents(array($parent));

Upvotes: 1

Related Questions