Specify folder name while upload file via Google Drive API

試著忘記壹切 提交于 2019-12-12 03:38:49

问题


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?


回答1:


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));


来源:https://stackoverflow.com/questions/32017234/specify-folder-name-while-upload-file-via-google-drive-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!