设想:
我将 .css 文件从一个子目录复制到 Azure 存储容器中的另一个子目录。它是在我的应用程序中从 C# 代码级别完成的。这是我网站的 css 样式文件。不幸的是,我在加载页面期间在浏览器控制台中收到错误:
错误
Resource interpreted as Stylesheet but transferred with MIME type application/octet-stream:
"SOME_PATH/template/css/styles.css?d=00000000-0000-0000-0000-000000000000".
知识:
我知道这就是为什么我的文件作为八位字节流而不是文本/css 发送的原因。我该怎么做才能说 Azure 将此文件视为文本/css?
编辑:我的代码
string newFileName = fileToCopy.Name;
StorageFile newFile = cmsDirectory.GetStorageFileReference(newFileName);
using (var stream = new MemoryStream())
{
fileToCopy.DownloadToStream(stream);
stream.Seek(0, SeekOrigin.Begin);
newFile.UploadFromStream(stream);
}
其中 DownloadToStream 和 UploadToStream 是我班级中的方法:
CloudBlob.DownloadToStream(target);
和
CloudBlob.DownloadToStream(target);
CloudBlob 是CloudBlockBlob类型
您可以通过属性 ContentType 设置 blob 的内容类型
查看:https : //docs.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.blob.blobproperties.contenttype
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句