在 Azure 存储上打开我的静态网站时,我会看到一个下载屏幕

Pet*_*sma 8 azure azure-storage

我使用静态网站功能在 Azure 存储上托管 ReactJS 应用程序。使用这个脚本:

$container = "`$web"
$context = New-AzureStorageContext -StorageAccountName $env:prSourceBranchName -StorageAccountKey "e4Nt0********dbFlEG2LN9g2i5/yQ=="
Get-ChildItem -Path $env:System_DefaultWorkingDirectory/_ClientWeb-Build-CI/ShellArtifact/out/build -File -Recurse | Set-AzureStorageBlobContent -Confirm:$false -Force -Container $container -Context $context
Run Code Online (Sandbox Code Playgroud)

我正在将文件从我的构建上传到 Azure 存储 $web blob。

在此输入图像描述

当我导航到静态页面的 URL 时,我会看到一个下载屏幕:

在此输入图像描述

当我删除所有文件并上传 simpel index.html 文件时,我确实加载了 index.html 文件:

https://gist.github.com/chrisvfritz/bc010e6ed25b802da7eb
Run Code Online (Sandbox Code Playgroud)

编辑

在 Edge 中我可以打开页面,但 Chrome 和 Firefox 会加载下载屏幕。但 Firefox 确实显示了更多信息:

在此输入图像描述

在此输入图像描述

所以看起来内容类型有点奇怪。

Iva*_*ang 11

根本原因应该是content-type不正确。

正如您已经提到的,当手动上传 .html 文件时,它的内容类型是“ text/html”。使用时Set-AzureStorageBlobContent变为“ application/octet-stream”。

解决方案是,在使用 powershell cmdlet 时Set-AzureStorageBlobContent,应该指定参数-Properties,如下所示:-Properties @{"ContentType" = "text/html"}

示例代码如下(它在我这边工作):

$context = New-AzureStorageContext -StorageAccountName "xxx" -StorageAccountKey "xxxxx"

#note that the last "\" is necessary
$path = "D:\temp\1\"

Get-ChildItem -Path $path  -File -Recurse | `
 %{ if($_.extension -eq ".html") {Set-AzureStorageBlobContent -File $_.FullName -Blob $_.FullName.Replace($path,'')  -Container "test-1" -Context $context -Properties @{"ContentType" = "text/html"}} `
 else {Set-AzureStorageBlobContent -File $_.FullName -Blob $_.FullName.Replace($path,'') -Container "test-1" -Context $context}}
Run Code Online (Sandbox Code Playgroud)

上面的代码只是将扩展名为.html的文件的content_type更改为“text/html”。您可以随意更改代码以满足您的需要。