【问题标题】:Google Drive API : error on insert file "Internal Error (Code : 4200)"Google Drive API:插入文件“内部错误(代码:4200)”时出错
【发布时间】:2014-04-22 18:51:46
【问题描述】:

我使用 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" --> "Unable to display this document yet"

Excel 文件在 Excel 中打开良好。

【问题讨论】:

    标签: php excel google-drive-api


    【解决方案1】:

    确保您的 $this->filemimetype 具有不带字符集部分的 mimetype。

    我遇到了完全相同的问题。
    原来这是由于传递给插入方法的 mimetype 不正确。
    当我尝试上传一个 excel 文件时,finfo_open(FILEINFO_MIME) 函数返回了 mimetype 以及附加的字符集信息,如下所示:"application/vnd.ms-excel; charset=binary"

    在将字符集传递给 Google_DriveFile 对象之前,我必须先删除该部分。

    $finfo = finfo_open(FILEINFO_MIME); 
    $mimetype = finfo_file($finfo, $filename);
    $mimetype = preg_replace('/;.*/','',$mimetype);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多