谷歌驱动器sdk转换上传的文件
问题描述:
我试图将上传的.doc转换为PHP Web应用程序中的Google Doc格式,以便我可以再以各种其他格式导出它。谷歌驱动器sdk转换上传的文件
我有这个...
$result = $service->files->create($file, array(
'data' => $data,
'mimeType' => 'application/msword',
'uploadType' => 'multipart'
));
但可悲的是新的API(V3)不支持“CONVER =真正的”参数...和文档说“提供的目标mime类型资源体“
如果我将mimeType
更改为=> 'application/vnd.google-apps.document'
我收到400错误... Invalid MIME type provided for the uploaded content
。
我错过了什么?
在此先感谢
答
如果是error 400,这可能意味着,未提供所需的字段或参数,提供的值是无效的,或者提供的字段的组合是无效的。
检查您是否将文件转换为当前支持的转换。请参阅Importing to Google Docs types了解更多信息。
尝试使用此示例代码:
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'My Report',
'mimeType' => 'application/vnd.google-apps.spreadsheet'));
$content = file_get_contents('files/report.csv');
$file = $driveService->files->create($fileMetadata, array(
'data' => $content,
'mimeType' => 'text/csv',
'uploadType' => 'multipart',
'fields' => 'id'));
printf("File ID: %s\n", $file->id);