gpt4 book ai didi

php - 如何使用 PHP 为谷歌云存储对象生成签名 URL

转载 作者:行者123 更新时间:2023-12-03 22:48:00 24 4
gpt4 key购买 nike

我尝试使用的方法是使用 openssl

$fp = fopen($key, 'r');  //open the PEM file
$priv_key = fread($fp,8192);
fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key,"password");

openssl_sign($response["data_to_sign"], $signature, $pkeyid,'sha256');

$sign = base64_encode($signature)

这是在 google 中为签名的 url 生成签名的正确方法吗?

最佳答案

你可以试试 Google Cloud Storage PHP SDK,它是保持代码干净的好选择。
云存储 PHP SDK
按照此页面将包安装到您的项目
on Packagist ,
然后

function getSignedGcsUrl($objPath/* which is your target object path */, $duration = 50) 
{
$storageClient = new StorageClient([
'projectId' => /* your gcp projectId here */,
'keyFilePath' => /* your gcp keyFilePath here */,
]);
$bucket = $storageClient->bucket($objPath);
$object = $bucket->object();
$url = $object->signedUrl(new \DateTime('+ ' . $duration . ' seconds'));
return $url;
}
laravel-google-cloud-storage(用于 Laravel)
按照此页面安装和配置 superbalist/laravel-google-cloud-storage:
on Github ,
然后
public static function getSignedGcsUrl($objPath, $duration = 50)
{
return Storage::disk('gcs'/* following your filesystem configuration */)
->getAdapter()
->getBucket()
->object($objPath)
->signedUrl(new \DateTime('+ ' . $duration . ' seconds'));
}

关于php - 如何使用 PHP 为谷歌云存储对象生成签名 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20493080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com