我看过这里问的问题: Friendly filename when public download Azure blob 我是一个完全天蓝色的菜鸟,并不知道如何实现任何答案,除了这个看起来像我能处理的东西:
string sasBlobToken = blob.GetSharedAccessSignature(sharedPolicy, new SharedAccessBlobHeaders()
{
ContentDisposition = "attachment; filename=" + friendlyFileName
});
string downloadLink = blob.Uri + sasBlobToken;
我的问题是如何正确设置' sharedpolicy变量?我试着在上面一行做一个空白的:
SharedAccessBlobPolicy sharedpolicy = new SharedAccessBlobPolicy();
但是在点击下载链接时我收到了拒绝权限的消息。所以我的问题是如何正确设置sharedpolicy变量?
答案 0 :(得分:5)
您收到此错误的原因是您未在SharedAccessBlobPolicy
中设置任何权限和权限到期。请尝试以下方法:
SharedAccessBlobPolicy sharedpolicy = new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,//Read permission because you want to download the file
SharedAccessExpiryTime = new DateTimeOffset(DateTime.UtcNow.AddHours(1))//The link will expire after 1 hour
};
string sasBlobToken = blob.GetSharedAccessSignature(sharedPolicy, new SharedAccessBlobHeaders()
{
ContentDisposition = "attachment; filename=" + friendlyFileName
});
string downloadLink = blob.Uri + sasBlobToken;