Azure Blob存储-下载和上载时的内容类型设置
我正在尝试使用C#将word文档上载到blob存储。代码片段如下所示:Azure Blob存储-下载和上载时的内容类型设置,azure,azure-storage,azure-storage-blobs,Azure,Azure Storage,Azure Storage Blobs,我正在尝试使用C#将word文档上载到blob存储。代码片段如下所示: var blobServiceClient = new BlobServiceClient(connectionString); var containerClient = blobServiceClient.GetBlobContainerClient(container); containerClient.CreateIfNotExists(PublicAccessType.None); var blobClient =
var blobServiceClient = new BlobServiceClient(connectionString);
var containerClient = blobServiceClient.GetBlobContainerClient(container);
containerClient.CreateIfNotExists(PublicAccessType.None);
var blobClient = containerClient.GetBlobClient(documentName);
using (var memoryStream = new MemoryStream({Binary of the File}))
{
var headers = new BlobHttpHeaders() { ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" };
await blobClient.UploadAsync(memoryStream, httpHeaders: headers).ConfigureAwait(false);
}
文档已成功上载到Blob存储。我可以看到,在查看Azure Storage Explorer时,内容类型也被正确设置。但是,当我尝试通过浏览器(chrome)访问此文档(使用文档URL)时,它会将该文件作为未知文件下载
我也尝试过通过Azure存储资源管理器上传word文档。此文件在通过浏览器下载时作为word文档下载
知道哪里出了问题吗?如下图所示,
内容类型
标题作为属性存储在Blob属性
中,因此它将被设置到下载响应的标题中,然后在通过浏览器下载时被识别为word文件
因此,在上载word文件时,有必要通过或为blob设置ContentType
属性
然后自己在服务器应用程序上编写下载响应标题的Content-Type
标题,标题值为contentType
Response<BlobProperties> response = await blobClient.GetPropertiesAsync();
var contentType = response.Value.ContentType
Response-Response=wait blobClient.GetPropertiesAsync();
var contentType=response.Value.contentType
或者从带有sas令牌的blob url下载响应,其中标头默认包括
ContentType
属性作为Content Type
标头。是否可以共享实际blob url?是否尝试了其他浏览器、EDGE或IE?