PHP 및 REST를 사용하여 Google 클라우드 저장소에 버킷을 만들려고합니다. 미국 지역에서는 양동이를 만들 수 있지만 EU 지역에서는 만들 수 없습니다.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 영역을 지정 했음에도 불구하고 미국 지역에 버킷을 만듭니다.
안녕하세요 Marc, 예 gsutil을 사용하여 버킷 생성을 테스트하고 있습니다. 나는 실제로 내 REST 요청이 0의 내용 길이를 가지고 것을 깨달았다 나는 것을 변경 : '의 나 strlen (XML_PAYLOAD)' 나는 당신이보고 정확한 오류 접수 : 'MalformedBucketConfiguration' 을' 제공 한 XML 형식이 올바르지 않거나 게시 된 스키마에 대해 유효성이 검증되지 않았습니다. " –
미국 및 EU 지역 모두에 대해 오류가 발생했음을 언급해야합니다. –
XML에 여는 물음표가 없습니다. xml': '(XML_PAYLOAD ',' ...') (doco의 경우) (https://developers.google.com/storage/docs/developer- 가이드 # speciflocations도) –