以下是我生成SAS:的方法
private string GenerateSasBlob(BlobClient blobClient)
{
BlobSasBuilder sasBuilder = new BlobSasBuilder()
{
BlobContainerName = blobClient.GetParentBlobContainerClient().Name,
BlobName = blobClient.Name,
Resource = "b",
StartsOn = DateTimeOffset.UtcNow,
ExpiresOn = DateTimeOffset.UtcNow.AddMonths(1),
Protocol = SasProtocol.Https,
ContentType = "mygzip"
};
sasBuilder.SetPermissions(BlobSasPermissions.Read);
return blobClient.GenerateSasUri(sasBuilder).ToString();
}
我认为通过指定ContentType可以修复它,但是生成的sas仍然下载为.gz,而不是预期的.mygzip.
虽然并排查看压缩文件中的内容是相同的,但我需要的是下载时应该是.mygzip。你知道怎么做吗?
考虑到您希望用不同的扩展名(mygzip而不是gz(下载blob,实际上您希望使用不同的名称下载blob。
在这种情况下,您想要覆盖的响应标头是Content-Disposition
,而不是Content-Type
。
你的代码应该是这样的:
private string GenerateSasBlob(BlobClient blobClient)
{
var newBlobName = blobClient.Name.Replace(".gz", ".mygzip");//Change the extension here in the name
BlobSasBuilder sasBuilder = new BlobSasBuilder()
{
BlobContainerName = blobClient.GetParentBlobContainerClient().Name,
BlobName = blobClient.Name,
Resource = "b",
StartsOn = DateTimeOffset.UtcNow,
ExpiresOn = DateTimeOffset.UtcNow.AddMonths(1),
Protocol = SasProtocol.Https,
ContentDisposition = $"attachment; filename="{newBlobName}""
};
sasBuilder.SetPermissions(BlobSasPermissions.Read);
return blobClient.GenerateSasUri(sasBuilder).ToString();
}
现在,当用户点击SAS URL时,blob将被下载;mygzip";扩大
有关Content Disposition标头的更多信息,请访问此处:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition.