[英]PhP - How do I block every EU country except the UK, and allow all non EU countries?
[英]How do I create a bucket in the EU region?
我正在尝试使用PHP和REST在Google云存储上创建存储桶。 我可以在美国地区创建好一个水桶,但似乎不能在欧盟地区创建一个水桶。
这是我在做什么-
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区域,但它只是在美国区域中创建了存储桶。
您如何判断它是否成功? gsutil -L?
我只是使用gsutil来指定位置,并使用-DD转储了请求的内容,并注意到在请求正文中发送的XML文档不包含XML标头。 接下来,我尝试使用curl使用类似的无标题XML文档来制定REST请求,它对我来说很好用。 接下来,我再次尝试使用XML标头进行curl,但由于以下错误而失败:
您提供的XML格式不正确或未针对我们发布的架构进行验证。
您可以重试不带XML标头的PHP代码,看看是否有帮助? 如果是这样,我可以为此提交一个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.