Convert and create a Google Drive Spreadsheet from a local CSV file via the Google Drive API -
i'm trying upload local csv-file google drive , display google spreadsheet there. however, when go google drive , click link file, can download it, not view spreadsheet. i've tried using ?convert=true file doesn't converted. i've tried using application/vnd.google-apps.spreadsheet
mime type noting changes or 400 bad request response.
exception 'google_serviceexception' message 'error calling post https://www.googleapis.com/upload/drive/v2/files?convert=true&uploadtype=multipart: (400) invalid mime type provided' in /var/www/html/twittery/lib/google-api-php-client/src/io/google_rest.php:66 stack trace: #0 /var/www/html/twittery/lib/google-api-php-client/src/io/google_rest.php(36): google_rest::decodehttpresponse(object(google_httprequest)) #1 /var/www/html/twittery/lib/google-api-php-client/src/service/google_serviceresource.php(186): google_rest::execute(object(google_httprequest)) #2 /var/www/html/twittery/lib/google-api-php-client/src/contrib/google_driveservice.php(484): google_serviceresource->__call('insert', array) #3 /var/www/html/twittery/generate_tweets_gspreadsheet.php(84): google_filesserviceresource->insert(object(google_drivefile), array) #4 {main}
the mimetype
uploading csv file should "text/csv".
as per documentation files:insert, make sure giving same mimetype
in
$file->setmimetype($mimetype);
and
$createdfile = $service->files->insert($file, array( 'data' => $data, 'mimetype' => $mimetype, 'convert' => true, ));
when creating or updating file in google drive, can convert uploaded file google docs, sheets or slides document using convert
query parameter.
you can refer page see support conversions each type of file upload.
Comments
Post a Comment