当我尝试使用使用天蓝色客户端存储库生成的 SAS 密钥时,我不断收到来自 Azure 存储服务的 403 身份验证错误。在调用代码上引发异常。
这是我得到的例外:
StatusMessage:Server failed to authenticate the request. Make sure the value of
Authorization header is formed correctly including the signature.
ErrorCode:AuthenticationFailed
这是正在生成的 SAS 密钥(最后的签名不准确,因为我不想分享它):
https://evinsight.blob.core.windows.net/jimsworld/jellyfish2.png?sv=2012-02-12&se=2013-08-29T03%3A36%3A52Z&sr=b&sp=w&sig=FJALKJFLKASJDF%JLKSDJLK%LJDLFKSDFJKL
这是调用代码:
/// Create the document and file objects and then return the fileAccessToken
/// <param name = "file_name"></param> */
public void GetSasInfoFromEb(string file_name)
{
/*********************************** EVINSIGHT TESTING CODE ********************************************/
try
{
AzureStorageTester ast = new AzureStorageTester();
BlobSasUri = ast.getStorageLibrarySas(file_name);
}
catch (Exception ex)
{
throw ex;
}
/***************************************************************************************************************/
}
/// Sends the whole small file to Azure Blob
public void WriteSmallFileToBlob()
{
int fileId = 0;
try
{
Blob = new CloudBlockBlob(new Uri(BlobSasUri));
Blob.UploadFromStream(File.InputStream);
File.InputStream.Close();
}
catch (Exception ex)
{
throw ex;
}
}
这是 SAS 生成代码:
/// <summary>
/// Returns the URI similar to how eB does it
/// </summary>
/// <param name="blobName">The name of the file being uploaded/downloaded</param>
/// <returns>The full uri for blob access</returns>
public string getStorageLibrarySas(string blobName)
{
string sasKey;
string uri;
setupBlobContainer();
blobName = blobName.ToLower();
_blob = _cloudRootContainer.GetBlockBlobReference(blobName);
sasKey = _blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Write,
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1)
});
return string.Format(CultureInfo.InvariantCulture, "{0}{1}", _blob.Uri, sasKey);
}
/// Creates the Blob Container
private void setupBlobContainer()
{
try
{
Microsoft.WindowsAzure.Storage.Auth.StorageCredentials credentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(_accountName, _accountKey);
// Create the storage account with the connection string
Microsoft.WindowsAzure.Storage.CloudStorageAccount _cloudStorageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(credentials, true);
_cloudBlobClient = _cloudStorageAccount.CreateCloudBlobClient();
_cloudRootContainer = _cloudBlobClient.GetContainerReference(_rootPath.ToLower());
_cloudRootContainer.CreateIfNotExists();
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Off;
_cloudRootContainer.SetPermissions(containerPermissions);
}
catch (Exception ex)
{
throw ex;
}
}
有任何想法吗?欣赏它!