0
votes

I use for more than one year the Drive API. But sometime, I have this error when uploading :

I made the upgrade to the 1.0.x version, but I still got this error, only on xls file.

"Error calling POST https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&convert=true: (500) Internal Error (Code : 4200)"

Here is the code for the insert, it work for every others files, exept xls.

    $createdFile = $this->service->files->insert($gdfile, array(
          'data' => $data,
          'mimeType' => $this->filemimetype,              
                'uploadType' => 'multipart',
          'convert' => true,
        ));

I have an error when I upload it on Drive via Chrome as well.

"Impossible d'afficher ce document pour l'instant" --> "Unable to display this document yet"

The Excel file open well in Excel.

1

1 Answers

0
votes

Make sure your $this->filemimetype has the mimetype without charset part.

I got exactly the same problem.
Turned out it was due to the incorrect mimetype passed to the insert method.
When I tried to upload an excel file finfo_open(FILEINFO_MIME) function returned the mimetype with the additional charset information like this: "application/vnd.ms-excel; charset=binary".

I had to strip out the part with the charset before passing it to the Google_DriveFile object.

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