Oauth 2.0 Picasa图像/视频可恢复上传问题
我正在尝试使用谷歌api可恢复上传选项上传视频/图像 如果我有200MB的文件,所以我必须做块上传N次。 我的代码返回308状态代码N-1次(最后一次除外)。对于最后一块,google没有响应我(我的php服务器显示“来自服务器的空回复”) 请帮助我哪里错了Oauth 2.0 Picasa图像/视频可恢复上传问题,oauth-2.0,google-drive-api,picasa,google-data-api,zend-gdata,Oauth 2.0,Google Drive Api,Picasa,Google Data Api,Zend Gdata,我正在尝试使用谷歌api可恢复上传选项上传视频/图像 如果我有200MB的文件,所以我必须做块上传N次。 我的代码返回308状态代码N-1次(最后一次除外)。对于最后一块,google没有响应我(我的php服务器显示“来自服务器的空回复”) 请帮助我哪里错了 global $access_token; $title = basename($videoPath); $mimeType = mime_content_type($videoPath); $content_length = getSiz
global $access_token;
$title = basename($videoPath);
$mimeType = mime_content_type($videoPath);
$content_length = getSize($videoPath);
$curl = new Curl();
$curl->setHeader("Host", "picasaweb.google.com");
$curl->setHeader("Content-Length", 0);
$curl->setHeader("X-upload-content-length", $content_length);
$curl->setHeader("X-upload-content-type", $mimeType);
$curl->setHeader("Slug", $title);
$curl->setHeader("Authorization", "Bearer $access_token");
$curl->setHeader("Content-Type", 'application/atom+xml');
$curl->setHeader("User-Agent", "CXchange-CXchange-1.0 cURL/1.11.3");
$curl->setHeader("Accept-encoding", "identity");
$curl->setHeader("GData-Version", "2");
$curl->setHeader("MIME-version", "1.0");
try {
//Get the resumable uri
$url = "https://picasaweb.google.com/data/upload/resumable/media/create-session/feed/api/user/default/albumid/$id";
$responce = $curl->post($url);
$responce_code = $curl->http_status_code;
if ($responce_code == 200) {
$headers = $curl->response_headers;
foreach ($headers as $header) {
if (strstr($header, "Location")) {
echo $uri = str_replace("Location:", "", $header);
break;
}
}
} else {
echo "Upload faild";
}
$cnt = 0;
$chunk_size = 256 * 1024 * 1;
$handle = fopen($videoPath, 'rb');
if ($handle === false) {
return false;
}
$progress = 0;
while (!feof($handle)) {
$buffer = fread($handle, $chunk_size);
$cnt = strlen($buffer);
$lastBytePos = $progress + $cnt - 1;
$curl = new Curl();
$curl->setHeader("Host", "picasaweb.google.com");
$curl->setHeader("Content-Length", $chunk_size);
$curl->setHeader("Authorization", "Bearer $access_token");
$curl->setHeader("Content-Type", $mimeType);
$curl->setHeader("User-Agent", "CXchange-CXchange-1.0 cURL/1.11.3");
$curl->setHeader("Accept-encoding", "identity");
$curl->setHeader("Content-Range", "bytes $progress-$lastBytePos/$content_length");
$curl->setHeader("GData-Version", "2");
$curl->setHeader("MIME-version", "1.0");
$curl->setHeader("Expect", "");
$responce = $curl->put(trim($uri), $buffer);
$responce_code = $curl->http_status_code;
if ($responce_code == 308) {
$headers = $curl->response_headers;
foreach ($headers as $header) {
if (strstr($header, "Range:")) {
$temp = explode("-", $header);
$progress = end($temp)+1;
break;
}
}
} else {
echo "Upload faild";
}
}
fclose($handle);
} catch (Exception $e) {
echo '';
}
代码:400
msg:文件过早结束
读完本主题后,是给第一个会话请求一些东西。你不能没有尸体就离开它
$xmldata =
'<entry xmlns="http://www.w3.org/2005/Atom">
<title>cats.jpg</title>
<summary>Real cat wants attention too.</summary>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/photos/2007#photo"/>
</entry>';
$request = new Google_Http_Request(
"https://picasaweb.google.com/data/upload/resumable/media/create-session/feed/api/user/{$person->id}/albumid/6185252512807301377?alt=json&access_token=" .$token['access_token'],
"POST",
array('GData-Version' => 2,
'Content-Type' => 'application/atom+xml',
'MIME-Version' => '1.0',
'Content-Length' => strlen($xmldata),
'X-Upload-Content-Length' => $size,
'X-Upload-Content-Type' => 'image/jpeg',
'Slug' => 'xxxx.jpg',
'Authorization' => "Bearer {$token['access_token']}"),
$xmldata
);
$response = Google_Http_REST::doExecuteRaw($client, $request);
$xmldata=
'
cats.jpg
真正的猫也需要注意。
';
$request=新的Google\u Http\u请求(
"https://picasaweb.google.com/data/upload/resumable/media/create-session/feed/api/user/{$person->id}/albumid/6185252512807301377?alt=json&access_-token=“.$token['access_-token'],
“职位”,
数组('GData-Version'=>2,
“内容类型”=>“应用程序/atom+xml”,
“MIME版本”=>“1.0”,
“内容长度”=>strlen($xmldata),
“X-Upload-Content-Length”=>size$,
'X-Upload-Content-Type'=>'image/jpeg',
'Slug'=>'xxxx.jpg',
'授权'=>“承载{$token['access_token']}”),
$xmldata
);
$response=Google\uhttp\urest::doExecuteRaw($client,$request);
Slug头是必需的,但文件名将是
cats.jpg
(xml)。您是否尝试发送另一个文件(可能是较小的文件)?