Excel文件(azure blob)不能在chrome中下载

Excel文件存储在azure blob容器中。 他们在IE浏览器下载没有事件,但在Chrome浏览器页面显示此消息(并在金丝雀崩溃):

This file appears corrupt 

并提供一个链接来下载它,所有这一切都是从这一点。 我试过将内容types设置为不同的Excel格式,但结果是一样的。

这是blob代码:

  MemoryStream memoryStream = new MemoryStream(); CreateFile(memoryStream, grid); memoryStream.Position = 0; var blockBlob = container.GetBlockBlobReference(randomFileName); blockBlob.Properties.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; blockBlob.DeleteIfExists(); var options = new BlobRequestOptions() { ServerTimeout = TimeSpan.FromMinutes(10) }; try { blockBlob.UploadFromStream(memoryStream, null, options); } catch (Exception e) { _logger.Error("Uploading excel file: Error: {0}", e.Message); } return new Uri("https://myblobs.blob.core.windows.net/" + "containername/" + randomFileName); 

你错过了blockBlob.SetProperties();

尝试这个:

  var blockBlob = container.GetBlockBlobReference(randomFileName); blockBlob.DeleteIfExists(); blockBlob.Properties.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; blockBlob.SetProperties(); // This is for commiting changes. 

请注意,对于.xls文件,您需要将content-type设置为application/vnd.ms-excel

仅供参考:如果要更新现有blob中的属性值,则需要获取当前值,设置要更新的属性并调用BLOB上的SetProperties

例:

  blob.FetchAttributes(); blob.Properties.ContentType = "image/png"; blob.SetProperties();