我不确定这里出了什么问题。我正在尝试显示当前存储在Azure文件存储中的图像。如果我直接在我的浏览器中链接,那么它似乎下载就好了。但当我把网址放在img src
然后我在控制台中收到此错误。
以下是我当前正在检索文件的URL:
public static string GetFile(Models.Core.Document file, string friendlyFileName = null)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
CloudFileShare share = fileClient.GetShareReference("organizations");
CloudFileDirectory fileDirectory = share.GetRootDirectoryReference().GetDirectoryReference("Org_" + file.OrgId);
// Get the file
var azureFile = (CloudFile)fileDirectory.ListFilesAndDirectories().First(f => f.Uri.ToString() == file.FilePath);
// Set up access policy so that the file can be viewed
var sasConstraints = new SharedAccessFilePolicy();
sasConstraints.SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5);
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(15);
sasConstraints.Permissions = SharedAccessFilePermissions.Read;
// Access token
var sasFileToken = string.Empty;
if (friendlyFileName != null){
sasFileToken = azureFile.GetSharedAccessSignature(sasConstraints, new SharedAccessFileHeaders()
{
ContentDisposition = "attachment; filename=" + friendlyFileName
});
}
else
{
sasFileToken = azureFile.GetSharedAccessSignature(sasConstraints);
}
// Return url to file with appended token
return azureFile.Uri + sasFileToken;
}
“不支持条件标头”究竟是什么意思?
“不支持条件标头”究竟是什么意思?
根据我的测试,您提到的代码中没有问题。根据Azure文件存储Get File API,没有指定支持条件头。因此,如果具有If条件标头的请求,则Azure文件服务器不接受它。它有时会发生在浏览器端,因为某些情况下的浏览器附加了if condition
标头。
如果Azure blob可以接受,请尝试使用Azure blob。然后它将按预期工作。支持条件标题的get blob api。
此操作还支持使用条件标头仅在满足指定条件时读取blob。有关更多信息,请参阅为Blob服务操作指定条件标头。