【发布时间】:2020-09-17 01:34:21
【问题描述】:
目标:将文件上传到 Azure Blob Storage,并设置用户下载文件时可以验证的 MD5。
使用 Azure CLI Powershell。
Get-FileHash -Algorithm MD5 .\AutoSetup.zip
Algorithm Hash Path
--------- ---- ----
MD5 693EF0DB938308AC2C362F50F7CB9F9F C:\MyFiles\AutoSetup.zip
az storage blob upload --account-name mystorageaccount --container-name mycontainername --file AutoSetup.zip --name Autosetup2.zip --content-md5 693EF0DB938308AC2C362F50F7CB9F9F
Finished[#############################################################] 100.0000%
The MD5 value specified in the request is invalid. MD5 value must be 128 bits and base64 encoded. ErrorCode: InvalidMd5
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidMd5</Code><Message>The MD5 value specified in the request is invalid. MD5 value must be 128 bits and base64 encoded.
RequestId:9f27334a-801e-0028-6db4-3539c5000000
Time:2020-05-29T12:28:23.7677258Z</Message></Error>
编辑 1:
我也尝试过以这种方式获取哈希
$someFilePath = "C:\MyFiles\AutoSetup.zip"
$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($someFilePath)))
Write-Host $hash
69-3E-F0-DB-93-83-08-AC-2C-36-2F-50-F7-CB-9F-9F
看来无论我做什么,为文件返回的MD5都是693EF0DB938308AC2C362F50F7CB9F9F,但Azure不会接受它...
编辑 2:
我生成了一个随机的 128 位字符串 $B&E)H@McQfTjWnZ 并继续在 Base64 中对其进行编码,这给了我 JEImRSlIQE1jUWZUalduWg== 当我尝试使用该哈希上传一个 blob 时,我收到一条不同的错误消息:
The MD5 value specified in the request did not match with the MD5 value calculated by the server. ErrorCode: Md5Mismatch
以上内容是有道理的,因为我刚刚创建了一个随机的 128 位 base64 编码哈希。但是,现在我想知道为什么 Powershell 的 Get-FileHash 命令给了我似乎不正确的信息?
什么可能导致错误?
【问题讨论】:
标签: azure powershell azure-blob-storage azure-cli