I'm trying to insert a user-submitted file into a specific folder named after the user, using yannisg's Google Uploader as base and a modified version of Google Drive example. The folder is created during the upload process. But I'm getting the above error about undefined id. Then it uploads the file into Drive's root folder. I'm using the v1-master of the PHP client.
function upload(){
$client = $this->client;
$service = $this->service; //$service = new Google_Service_Drive($client);
//Create folder
$folder = new Google_Service_Drive_DriveFile(array(
'mimeType' => 'application/vnd.google-apps.folder'));
$folder->setTitle($this->ownerName); //applicant's name
$folderData = $service->files->insert($folder, array(
'fields' => 'id'));
//create file
$file = new Google_Service_Drive_DriveFile();
$file->title = $this->fileName;
$chunkSizeBytes = 1 * 1024 * 1024;
$fileRequest = $this->fileRequest;
$mimeType = $this->mimeType;
//Set parent id
$parent = new Google_Service_Drive_ParentReference();
$parent->setId($folderData->id);
$file->setParents(array($parent));
$request = $service->files->insert($file);
//The rest of the script...
}
I think the problem lies here
$parent->setId($folderData->id);
Here's the same portion from the modified example script that works nicely. I would've have used this but I can't seem to properly integrate it into another script I need to run. And yannisg's have the refresh token taken care of.
//Create folder
$folder = new Google_Service_Drive_DriveFile(array(
'mimeType' => 'application/vnd.google-apps.folder'));
$folder->setTitle($_FILES["uploaded"]["name"]); //applicant's name
$folderData = $service->files->insert($folder, array(
'fields' => 'id'));
var_dump($folderData);
//Create file
$file = new Google_Service_Drive_DriveFile();
$file->title = $_FILES["uploaded"]["name"];
$chunkSizeBytes = 1 * 1024 * 1024;
//Set parent id
$parent = new Google_Service_Drive_ParentReference(); //previously Google_ParentReference
$parent->setId($folderData->id);
$file->setParents(array($parent));
Var dumping the second script gives me object(Google_Service_Drive_DriveFile) while the first gave object(Google_Http_Request). Is it because the first one is in a class?
Thanks in advance.