无法使用已签名的网址与gcloud存储一起使用。
我知道这里可能有一些简单的东西,但我找不到它。
尝试按照此处的说明https://cloud.google.com/storage/docs/access-control/create-signed-urls-program
为gcloud存储桶中的文件创建已签名的网址创建一个servive帐户并下载pk12并将p12转换为pem以获取密钥。
这是代码:
$pkeyid = "-----BEGIN RSA PRIVATE KEY-----
[removed actual key]
-----END RSA PRIVATE KEY-----";
$secret = "notasecret";
$expires = time()+86400;
$http_method = "GET";
$bucketName = "mybucketname";
$stringtosign = "GET\n
\n
text/plain\n
".$expires."\n
\n
\n
\n
".$bucketName ."/mymediafile.mp4";
openssl_sign($stringtosign, $signature, $pkeyid);
$emailid="serviceaccount@[project].iam.gserviceaccount.com";
$signature = urlencode(base64_encode($signature));
$gcloudloc = "https://storage.googleapis.com/".$bucketName ."/mymediafile.mp4?GoogleAccessId=".$emailid."&Expires=".$expires."&Signature=".$signature;
我看起来像一个有效的签名,但当我尝试使用完整的URL我得到
The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
答案 0 :(得分:0)
我有两个问题:
我找到了这个“Google Cloud Storage Signed Url for media”,并且能够使用hdezela中的函数(如下)来使其正常工作!
function storageURL($bucket,$archivo) {
$expires = time()+60;
$to_sign = ("GET\n\n\n".$expires."\n/".$bucket.'/'.$archivo);
$fp = fopen('/path/to/google.pem', 'r');
$priv_key = fread($fp, 8192);
fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key);
if(!openssl_sign($to_sign,$signature,$pkeyid,'sha256')) {
$signature = 'sinfirma';
} else {
$signature = urlencode(base64_encode($signature));
}
return ('https://'.$bucket.'.storage.googleapis.com/'.$archivo.'?GoogleAccessId=XXXXXXX@developer.gserviceaccount.com&Expires='.$expires.'&Signature='.$signature);
}
我原本以为这是网址,但也可以。
"https://storage.googleapis.com/".$bucketName ."/