【发布时间】:2014-12-15 20:21:27
【问题描述】:
我尝试使用 PHP 创建指向 blob 资源的 SAS 链接。不幸的是,目前在 azure SDK 中没有创建 SAS 签名的方法。 我编写了用于生成 SAS 的代码,但是当我尝试通过此方法生成的链接获取资源时,我收到以下消息:签名字段格式不正确。
public function getSharedAccessSignatureURL($container, $blob)
{
$signedStart = date('c', strtotime('-1 day'));
$signedExpiry = date('c', strtotime('+1 day'));
$signedResource = 'b';
$signedPermission = 'r';
$signedIdentifier = '';
$responseContent = "file; attachment";
$responseType = "binary";
$canonicalizedResource = '/'.$this->account['accountName'].'/'.$container.'/'.$blob;
$signedVersion = '2014-02-14';
$stringToSign =
$signedPermission."\n".
$signedStart."\n".
$signedExpiry."\n".
$canonicalizedResource."\n".
$signedIdentifier."\n".
$signedVersion;
$signature = base64_encode(
hash_hmac(
'sha256',
urldecode(utf8_encode($stringToSign)),
$this->account['primaryKey'],
true
)
);
$arrayToUrl = [
'sv='.urlencode($signedVersion),
'st='.urlencode($signedStart),
'se='.urlencode($signedExpiry),
'sr='.urlencode($signedResource),
'sp='.urlencode($signedPermission),
'rscd='.urlencode($responseContent),
'rsct='.urlencode($responseType),
'sig='.urlencode($signature)
];
$url = 'https://'.$this->account['accountName'].'.blob.core.windows.net'.'/'
.$container.'/'
.$blob.'?'.implode('&', $arrayToUrl);
return $url;
}
任何建议我做错了什么?我是 Microsoft Azure 的新手
【问题讨论】:
-
你是先用谷歌搜索的吗? social.msdn.microsoft.com/Forums/en-US/… 。只是好奇-
-
是的。但是对于PHP来说并没有太多。我真的不明白,尤其是我尝试遵循文档。 msdn.microsoft.com/en-US/library/azure/dn140255.aspx有经验的有什么建议吗?
标签: php azure azure-blob-storage