Anybody can help me with this?
Server failed to authenticate the request. Signature did not match. String to sign used was r
function generateBlobSasToken(
$storageAccountName,
$containerName,
$blobName,
$accountKey
) {
$start = gmdate('Y-m-d\TH:i:s\Z', time());
$expiry = gmdate('Y-m-d\TH:i:s\Z', strtotime('+1 day'));
$permissions = 'r'; // Read permission
$serviceVersion = '2020-08-04'; // Service version
$resource = "b"; // Resource type
// Construct the string-to-sign
$stringToSign = "$permissions\n"
. "$start\n"
. "$expiry\n"
. "/$storageAccountName/$containerName/$blobName\n"
. "$serviceVersion\n\n\nhttps\n";
$signature = base64_encode(hash_hmac('sha256', $stringToSign, base64_decode($accountKey), true));
$sasToken = "sp=$permissions"
. "&st=" . str_replace(':', '%3A', $start)
. "&se=" . str_replace(':', '%3A', $expiry)
. "&sr=$resource"
. "&sv=$serviceVersion"
. "&spr=https"
. "&sig=$signature";
return $sasToken;
}
function generateBlobUrl(
$storageAccountName,
$containerName,
$blobName,
$accountKey
) {
$sasToken = generateBlobSasToken($storageAccountName, $containerName, $blobName, $accountKey);
$blobUrl = "https://$storageAccountName.blob.core.windows.net/$containerName/$blobName?$sasToken";
return $blobUrl;
}
creates url like https://{{accountName}}.blob.core.windows.net/container1/fdg.pdf?sp=r&st=2023-10-24T10%3A01%3A17Z&se=2023-10-25T10%3A01%3A17Z&sr=b&sv=2020-08-04&spr=https&sig={{key}}
but when i go to this url i can see above error. Anybody can help me?