PHP と REST を使用して Google クラウド ストレージにバケットを作成しようとしています。米国リージョンでは問題なくバケットを作成できますが、EU リージョンではバケットを作成できないようです。
これが私がやっていることです -
function createBucket($accessToken, $bucket, $region)
{
$version_header = "x-goog-api-version: 2";
$project_header = "x-goog-project-id: ".$this->projectID;
$url = 'https://'.$bucket.'.commondatastorage.googleapis.com';
$timestamp = date("r");
define('XML_PAYLOAD','<xml version=\'1.0\' ? ><CreateBucketConfiguration><LocationConstraint>'.$region.'</LocationConstraint></CreateBucketConfiguration>');
$headers = array(
'Host: '.$bucket.'.commondatastorage.googleapis.com',
'Date: '.$timestamp,
$version_header,
$project_header,
'Content-Length: 0',
'Authorization: OAuth '.$accessToken);
$c = curl_init($url);
curl_setopt($c, CURLOPT_HEADER, 1);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_HTTPHEADER,$headers);
curl_setopt($c, CURLOPT_POSTFIELDS,XML_PAYLOAD);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, "PUT");
$response = curl_exec($c);
curl_close($c);
// split up the response into header and xml body
list($header, $xml) = explode("\r\n\r\n", $response, 2);
// tokenize - first token is the status
$status = strtok($header, "\r\n");
if(stristr($status,"200 OK"))
{
//success
$result = "success";
}
else
{
//failed
$result = "fail";
}
return $result;
}
この関数は、米国のバケットでは正常に機能しますが、EU の場合は失敗します。バケット用に生成された名前が一意の名前であることを確認しています (米国のバケットでも同じパターンが機能します)。
編集:実際には関数は失敗しません。バケットを作成します... EU 地域を指定しているにもかかわらず、米国地域にバケットを作成するだけです。