I have a PHP app that saves some information into a .CSV file. I want to upload it to my Google Drive.
This seems to upload the file:
$service = new Google_Service_Drive($client);
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'file.csv',
'parents' => [$FOLDER_ID]
));
$file = $service->files->create($fileMetadata, array(
'data' => $product_data,
'mimeType' => 'application/octet-stream',
'uploadType' => 'multipart',
'fields' => 'id'
));
This has some weird issues:
-
To upload it to a specific folder, I have to know the FILE ID, as opposed to simply adding the path.
-
It will continuously add files with the same name instead of overwriting the file.
After some research, I can use $service->files->update to overwrite the existing file. However, to do that, I would need to know the $file_id.
Is there a way to upload files using the path, as opposed to IDS?
Is there a way to create the file if it doesn’t exist, or overwrite it if it does?
I can only think of two ways to do this:
- Hardcode the file name and DIR ids, then update it if it ever changes.
- Write code that scans the drive to figure out if the folder and file ids
I am adapting from the Dropbox API, which comparatively was much more intuitive.
Any help is appreciated – thanks