使用 REST 将 blob 上传到 Azure 存储时出错 - 请求 URI 中指定的查询参数之一的值无效

Error uploading blob to Azure Storage using REST - Value for one of the query parameters specified in the request URI is invalid

我正在尝试使用 REST API.

将 blob 上传到 Azure 存储帐户

正如在许多文档中所读,我首先创建文件:

$headers = @{
   'x-ms-blob-type' = 'BlockBlob'
}

对 SAS URI 调用 PUT 操作(直接从 Azure 门户复制)

https://mystorage.blob.core.windows.net/pdf/agb_megasim.pdf?sp=rac&st=2021-06-30T09:52:08Z&se=2021-07-31T17:52:08Z&spr=https&sv=2020-02-10&sr=c&sig=uhuEFp%2Bl1MJO%2B8dfsUYkfpegPK9KeYPOPsN08govKGg%3D

接下来,我将向 url 发送 (PUT) 一个字节流。 SAS url 修改为添加 comp=range

$headers = @{
    "x-ms-version" = "2015-02-21"
    "x-ms-range"   = "bytes=0-86751"
    "x-ms-date"    = "7/5/2021 4:55:47 PM"
    "x-ms-write"   = "update"
    'x-ms-blob-type' = 'BlockBlob' 
}
https://mystorage.blob.core.windows.net/pdf/agb_megasim.pdf?**comp=range**&sp=rac&st=2021-06-30T09:52:08Z&se=2021-07-31T17:52:08Z&spr=https&sv=2020-02-10&sr=c&sig=uhuEFp%2Bl1MJO%2B8dfsUYkfpegPK9KeYPOPsN08govKGg%3D
<?xml version="1.0" encoding="utf-8"?>
<Error>
    <Code>InvalidQueryParameterValue</Code>
    <Message>Value for one of the query parameters specified in the request URI is invalid.
RequestId:bd905701-d01e-0036-6fbc-71bbbf000000
Time:2021-07-05T16:42:26.9354872Z</Message>
</Error>

这似乎是我尝试过的各种文档中的程序,但对我不起作用! 我尝试使用 Powershell 和邮递员。

知道是哪个参数导致了问题吗?

此外,这就是我打算传递文件内容的方式: 读取文件

$fileContentBytes = [System.IO.File]::ReadAllBytes($file)

不确定,如果需要编码,

[System.Convert]::ToBase64String($fileContentBytes)

考虑到您正在执行 Put Blob 操作并尝试创建 Block Blob,您无需在查询字符串中指定 comp=range 参数。请通过删除它来尝试您的操作。

此外,您需要在请求中提供的唯一 header 是 x-ms-blob-type。您可以从请求中删除所有其他 header。