【问题标题】:Storing Excel/Word documents Windows Azure Blob Storage Files Corrupted存储 Excel/Word 文档 Windows Azure Blob 存储文件损坏
【发布时间】:2012-10-12 08:30:57
【问题描述】:

我们已经开始使用 Azure blob storage api 在我们的网站上存储上传的 blob,图像工作正常,但是当我们上传 word/excel 文档并返回 Url 并尝试从该 url 下载文件并打开它时我们在 Excel 或 Word 中收到错误提示:

“Excel 无法打开文件“somefile.xlsx”,因为格式或文件扩展名无效。请确认文件没有损坏并且文件扩展名与文件格式匹配”。

我知道我一定遗漏了一些明显但不确定是什么,下面是我们正在使用的代码:

  CloudBlobContainer container = GetCloudBlobContainer();

  Guid guid = Guid.NewGuid();
  string storeFilename = String.Concat(mediaType.ToString(), "/", guid, "_", filename);

  var blob = container.GetBlobReference(storeFilename);
  blob.Properties.ContentType = contentType;
  blob.UploadFromStream(stream);

  return blob.Uri.AbsolutePath;

我们返回 URL 并将其存储在已上传的文件中,并将其用作下载文件的链接。

文件下载正常,与上传的大小完全相同,但无法打开。

任何帮助都将不胜感激,因为它一定很明显,但我害怕它躲避我。

【问题讨论】:

    标签: c# asp.net-mvc azure-storage


    【解决方案1】:

    您使用什么代码将文档保存到 Azure?

    上传和下载时 ContentType 的值是多少?

    您是否对上传流进行了 UTF8 编码?

    查看this upload example,它在上传之前设置了 ContentType 和 UTF8 编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-08
      • 2018-07-12
      • 2014-02-08
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 2017-08-18
      • 1970-01-01
      相关资源
      最近更新 更多