Search code examples
phpcurlgoogle-docsgoogle-docs-api

There is an empty file after updating


I'm trying to update an existing document with help of Google Docs API. I'm using PHP+Curl. The gdata.class.php is base class. Updating finishes partly. A old content is cleaned. But a new content is not created. According to documentation, I send PUT-request (initial request) to address

http://docs.google.com/feeds/upload/create-session/default/private/full/document%123456

There are Etag of the document and the empty request body. I recive the status code 200 Ok and the unique upload URI like this:

http://docs.google.com/feeds/upload/create-session/default/private/full/document%123456?upload_id=EnB2Uob7DWcFVJTX3oF8sdVv9koZTHacngmM_

What should I do???

  1. I'm sending the file content and headers to the unique upload URI:

    [0] => Content-Length: 6 
    [1] => Content-Range: bytes 0-5/6 
    [2] => Content-Type: text / plain
    

    The responce is recived:

    HTTP/1.1 308 Resume Incomplete

    Headers not contains the "Range" header. It's strange. Result: the target file is not changed.

  2. I'm sending the file content and headers to the unique upload URI:

    [0] => Content-Length: 6
    [1] => Content-Type: text/plain
    

    The responce is recived:

    HTTP/1.1 200 OK
    

    There is atom+xml in the body. Result: the target file became an empty.

P.s. The curl_getinfo function returns "5". It's not depends on size of the file.


Solution

  • Well if it asks you to use PUT method, then tell CURL to use it..

    curl_setopt($ch, CURLOPT_PUT, 1);