我以这种方式为文件生成 SAS 令牌:
private string GeFileSASToken(CloudFile file)
{
SharedAccessFilePolicy policy = new SharedAccessFilePolicy()
{
Permissions = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.Write | SharedAccessFilePermissions.List,
SharedAccessStartTime = DateTime.Now,
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
};
return file.GetSharedAccessSignature(policy);
}
如果我在浏览器中打开带有此令牌的文件链接,一切正常并下载文件。但是如果我尝试像这样在 Viewerjs 中使用这个链接:
<iframe src = "http://mydomain/ViewerJS/index.html#blob:https://myazureaccount.file.core.windows.net/myshare/mydirectorypath/myfile?SASTOKEN" width='300' height='300'></iframe>
我看到错误消息:
无法加载 blob:https ://myazureaccount.file.core.windows.net/myshare/mydirectorypath/myfile?SASTOKEN:跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https。