@Gobinath Vartharaju (DE-SWE/DIGITAL) Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
It looks like you're encountering an issue with the SAS token containing a "+" sign, which is causing compatibility issues with the browser. This is a common problem because the "+" character in URLs is often interpreted as a space by browsers.
To resolve this issue, you can URL-encode the SAS token before using it in the browser. The "+" character should be replaced with "%2B". Here's how you can modify your code to URL-encode the SAS token:
private static string GenerateBlobSasToken(BlobContainerClient containerClient, string blobFullPath)
{
// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(blobFullPath);
// Ensure the blob exists
if (!blobClient.Exists())
{
throw new Exception($"Blob {blobFullPath} does not exist.");
}
BlobSasBuilder sasBuilder = new BlobSasBuilder
{
BlobContainerName = containerClient.Name,
BlobName = blobFullPath,
Resource = "b", // 'b' indicates that the shared access signature is for a blob
ExpiresOn = DateTimeOffset.UtcNow.AddDays(1).AddHours(1), // Set the expiry time for the SAS token,
StartsOn = DateTimeOffset.UtcNow.AddSeconds(-30), //Set the start time for the token (buffer by 30s)
ContentType = "application/x-mpegurl",
Protocol = SasProtocol.Https
};
// Set the permissions for the SAS token
sasBuilder.SetPermissions(BlobSasPermissions.Read);
// Use the storage account key to sign the SAS token
Uri sasUri = blobClient.GenerateSasUri(sasBuilder);
// URL-encode the SAS token
string encodedSasUri = Uri.EscapeUriString(sasUri.ToString());
Console.WriteLine($"Generated SAS Url for : {blobFullPath} - {encodedSasUri} - {sasUri.AbsoluteUri}");
return encodedSasUri;
}
This should ensure that the SAS token is compatible with the browser.
It looks like the SAS token is working correctly with CURL, as indicated by the HTTP/1.1 200 OK
response. The issue with the "+" sign in the SAS token causing compatibility problems in the browser can be resolved by URL-encoding the token.
In your CURL command, the SAS token is URL-encoded, which is why it works. The "+" sign is replaced with %2B
, and other special characters are also encoded. This ensures that the token is interpreted correctly by the browser.
If you haven't already, you can modify your code to URL-encode the SAS token before using it in the browser. Here's the updated code snippet:
Option 2:
you can try URL encoding the signature before appending it to the SAS token. You can use the HttpUtility.UrlEncode
method in the System.Web
namespace to URL encode the signature.
This code snippet uses the HttpUtility.UrlEncode
method to URL encode the signature before appending it to the SAS token. This should ensure that the SAS token is compatible
Please let us know if you have any further queries. I’m happy to assist you further.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.