[英]Azure File Storage API access using Shared Access Signature
I'm currently trying to access files & directories on an Azure Storage Account Fileshare (let's call it rootdirectory ) from a Dynamics Business Central page action. 我目前正在尝试通过Dynamics Business Central页面操作访问Azure存储帐户Fileshare (称为rootdirectory )上的文件和目录。
The method to access files stored in it is to build and send an HTTP GET request (with a client) to https://myaccount.file.core.windows.net/myfileshare/rootdirectory to retrieve a filelist. 访问存储在其中的文件的方法是构建HTTP GET请求(使用客户端)并将其发送到https://myaccount.file.core.windows.net/myfileshare/root目录,以检索文件列表。
I'm trying to use a Shared Access Signature to authenticate the request. 我正在尝试使用共享访问签名来验证请求。
The blocking point that I can't get through is the following error message : 我无法通过的阻止点是以下错误消息:
Authentication information is not given in the correct format. Check the value of Authorization header.
I'm setting my request headers like this : 我正在这样设置我的请求标头:
client.DefaultRequestHeaders().Clear();
client.DefaultRequestHeaders().Add('x-msdate', '2019-02-20');
client.DefaultRequestHeaders().Add('Authorization', '...');
My main problem is that I can't seem to find the proper format (to use in the '...' part) asked in the error message in any tutorial . 我的主要问题是,我似乎找不到任何教程中错误消息中要求的正确格式(在“ ...”部分中使用)。
I've tried the following formats (and minor variations inside it) 我尝试了以下格式(其中的细微变化)
'SharedAccessSignature myaccount:signature'
'SharedAccessSignature sv=2018-03-28&ss=f&srt=sco&sp=rwdlc&se=2019-02-20T18:12:27Z&st=2019-02-20T10:12:27Z&spr=https&sig=signature'
'SharedAccessSignature sr=https%3A%2F%2Fmyaccount.file.core.windows.net%2Fmyfileshare%2Frootdirectory&sig=signature&se=2019-02-21T22:36:05Z&skn=key1'
I also tried putting it in the service URI, nothing better. 我还尝试将其放在服务URI中,再好不过了。
Has anyone already encountered this issue ? 有人遇到过这个问题吗?
Any help would be appreciated. 任何帮助,将不胜感激。
Thanks for your time. 谢谢你的时间。
I would highly recommend checking the following post . 我强烈建议您检查以下帖子 。 They ended up using the below code:
他们最终使用以下代码:
public AzureSASToken GetSASFromShare(string shareName)
{
var share = _fileclient.GetShareReference(shareName);
share.CreateIfNotExists();
string policyName = "UPARSharePolicy";
// Create a new shared access policy and define its constraints.
var sharedPolicy = new SharedAccessFilePolicy()
{
SharedAccessExpiryTime = DateTime.UtcNow.AddDays(15),
Permissions = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.Write
};
// Get existing permissions for the share.
var permissions = share.GetPermissions();
// Add the shared access policy to the share's policies.
// Note that each policy must have a unique name.
// Maximum 5 policies for each share!
if (!permissions.SharedAccessPolicies.Keys.Contains(policyName))
{
if (permissions.SharedAccessPolicies.Count > 4)
{
var lastAddedPolicyName = permissions.SharedAccessPolicies.Keys.Last();
permissions.SharedAccessPolicies.Remove(lastAddedPolicyName);
}
permissions.SharedAccessPolicies.Add(policyName, sharedPolicy);
share.SetPermissions(permissions);
}
var sasToken = share.GetSharedAccessSignature(sharedPolicy);
//fileSasUri = new Uri(share.StorageUri.PrimaryUri.ToString() + sasToken);
return new AzureSASToken ()
{
Name = shareName,
Url = share.StorageUri.PrimaryUri.ToString() + "/",
SASToken = sasToken
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.