我試圖使用PHP創建SAS鏈接到blob資源。不幸的是,目前在Azure SDK中沒有創建SAS簽名的方法。 我寫了一個代碼來生成SAS,但當我試圖通過此方法生成的鏈接獲取資源時,我收到此消息:簽名字段結構不正確。Microsoft Azure和SAS for PHP
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;
}
任何暗示我做錯了什麼?我是微軟Azure的新手
你先google嗎? https://social.msdn.microsoft.com/Forums/en-US/03979c33-dc9d-4711-8f8a-fce1a5ebc476/getting-random-exception-while-downloading-blobs?forum=windowsazuremanagement。只是好奇 - – ChrisG 2014-10-20 19:08:02
是的。但是PHP並沒有太多的功能。我真的不明白,特別是我嘗試按照文檔。 http://msdn.microsoft.com/en-US/library/azure/dn140255.aspx 有經驗的任何建議嗎? – bliszka 2014-10-20 22:54:33