Fix upload for Google Drive; Google Documents List API documentation was misleading

This commit is contained in:
Michael Gapczynski 2012-06-14 20:56:48 -04:00
parent f6aa366857
commit 92083aa20c
1 changed files with 9 additions and 7 deletions

View File

@ -40,7 +40,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
$this->entries = array(); $this->entries = array();
} }
private function sendRequest($uri, $httpMethod, $postData = null, $extraHeaders = null, $isDownload = false, $returnHeaders = false, $isContentXML = true) { private function sendRequest($uri, $httpMethod, $postData = null, $extraHeaders = null, $isDownload = false, $returnHeaders = false, $isContentXML = true, $returnHTTPCode = false) {
$uri = trim($uri); $uri = trim($uri);
// create an associative array from each key/value url query param pair. // create an associative array from each key/value url query param pair.
$params = array(); $params = array();
@ -108,6 +108,8 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
if ($httpCode <= 308) { if ($httpCode <= 308) {
if ($isDownload) { if ($isDownload) {
return $tmpFile; return $tmpFile;
} else if ($returnHTTPCode) {
return array('result' => $result, 'code' => $httpCode);
} else { } else {
return $result; return $result;
} }
@ -425,7 +427,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
$etag = $entry->getAttribute('gd:etag'); $etag = $entry->getAttribute('gd:etag');
$links = $entry->getElementsByTagName('link'); $links = $entry->getElementsByTagName('link');
foreach ($links as $link) { foreach ($links as $link) {
if ($link->getAttribute('rel') == 'http://schemas.google.com/g/2005#resumable-edit-media') { if ($link->getAttribute('rel') == 'http://schemas.google.com/g/2005#resumable-create-media') {
$uploadUri = $link->getAttribute('href'); $uploadUri = $link->getAttribute('href');
break; break;
} }
@ -461,12 +463,12 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
} }
} }
$end = $i + $chunkSize - 1; $end = $i + $chunkSize - 1;
$headers = array('Content-Length: '.$chunkSize, 'Content-Type: '.$mimetype, 'Content Range: bytes '.$i.'-'.$end.'/'.$size); $headers = array('Content-Length: '.$chunkSize, 'Content-Type: '.$mimetype, 'Content-Range: bytes '.$i.'-'.$end.'/'.$size);
$postData = fread($handle, $chunkSize); $postData = fread($handle, $chunkSize);
$result = $this->sendRequest($uploadUri, 'PUT', $postData, $headers, false, true, false); $result = $this->sendRequest($uploadUri, 'PUT', $postData, $headers, false, true, false, true);
if ($result) { if ($result['code'] == '308') {
// Get next location to upload file chunk if (preg_match('@^Location: (.*)$@m', $result['result'], $matches)) {
if (preg_match('@^Location: (.*)$@m', $result, $matches)) { // Get next location to upload file chunk
$uploadUri = trim($matches[1]); $uploadUri = trim($matches[1]);
} }
$i += $chunkSize; $i += $chunkSize;