I have some old code that inserts a csv file into a Google Drive account and it was opened by Google Spreadsheets by default.
Couple days ago I started to receive this error message:
There is some problems with the Google connection. Please, try again. (Error calling POST https://www.googleapis.com/upload/drive/v2/files?convert=false&uploadType=multipart&key=XXXXXXXXXXXXXXX: (400) Invalid mime type provided)
Here is some of the code:
public function createDriveFile($tmpFilePath,$title,$fileMimetype = '',$description = '',$googleDocmimeType = ''){
$file = new Google_DriveFile();
$file->setTitle($title);
$file->setDescription($description);
$data = file_get_contents($tmpFilePath);
$optParams = array('data' => $data);
if($fileMimetype != '' ) {
if($fileMimetype === 'text/csv' ) {
$optParams['convert'] = false;
$optParams['mimeType'] = 'application/vnd.google-apps.spreadsheet';
} else {
$optParams['convert'] = true;
}
$file->setMimeType( $fileMimetype );
}
if ($googleDocmimeType != ''){
$optParams['mimeType'] = $googleDocmimeType;
}
$createdFile = $this->_driveService->files->insert($file, $optParams);
return $createdFile;
}
I'm pretty sure that it is sending 'application/vnd.google-apps.spreadsheet'
as mimetype.
Here a call to that function:
$createFileInfo = $googleOauth->createDriveFile('/tmp/file.csv', 'file.csv','text/csv');
I made some tests changing the value of the 'convert'
parameter to true
and didn't work.