Hi. Anyone know how to post file using curl to the google documents. I write this code:
$header[] = "Authorization: GoogleLogin auth=seсretkey";
$header[] = "Content-Type: application/pdf";
$header[] = "Slug: testdoc";
$header[] = "Content-Length: ".$_FILES['file']['size']."";
$url = "http://docs.google.com/feeds/documents/private/full";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($_FILES['file']['tmp_name']));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
And it works fine only if i use plain/text Content-type with text files, but if my uploaded file in binary mode i got 417 http error code, for example with pdf documents.
I've trying change this line
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($_FILES['file']['tmp_name']));
To this
curl_setopt($ch, CURLOPT_POSTFIELDS, array("file"=>"@".$_FILES['file']['tmp_name']));
But i've got 417 response error code again. Only with plain/text response is 201.
Example of the google documents upload headers from official source
POST /feeds/documents/private/full HTTP/1.1
Host: docs.google.com
Authorization: <your authorization header here>
Content-Length: 81047
Content-Type: application/vnd.ms-excel
Slug: Example Spreadsheet
... spreadsheet contents here ...