我使用了一年多的Drive API。但有时,我有这个错误时,上传:
我升级到1.0。x版本,但我仍然得到这个错误,只有在xls文件。
" POST调用错误https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&convert=true:(500)内部错误(代码:4200)"
这是插入的代码,它适用于所有其他文件,除了xls。
$createdFile = $this->service->files->insert($gdfile, array(
'data' => $data,
'mimeType' => $this->filemimetype,
'uploadType' => 'multipart',
'convert' => true,
));
我有一个错误,当我上传它通过Chrome驱动器以及。
"Impossible d'afficher ce document pour l'instant" -> "暂无法显示此文档"
Excel文件在Excel中打开良好
确保您的$this->filemimetype
具有不带字符集部分的mime类型
我也遇到同样的问题。
原来是由于传递给insert方法的mime类型不正确。
当我试图上传一个excel文件finfo_open(FILEINFO_MIME)
函数返回mime类型与额外的字符集信息,像这样:"application/vnd.ms-excel; charset=binary"
.
在将其传递给Google_DriveFile对象之前,我必须去掉带有字符集的部分。
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $filename);
$mimetype = preg_replace('/;.*/','',$mimetype);