gpt4 book ai didi

Azure Blob 存储 : Unable to upload the blob with size 0

转载 作者:行者123 更新时间:2023-12-03 04:29:49 26 4
gpt4 key购买 nike

我们的应用程序要求上传大小为 0 的 blob。我们使用 cURL 来调用 Azure 存储 REST API。上传大小时失败,并显示 HTTP 错误代码 [400]

返回以下错误消息

<小时/>
<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>InvalidHeaderValue</Code>
<Message>
The value for one of the HTTP headers
is not in the correct format.
RequestId:2b1ec18b-0001-007d-7811-e40725000000
Time:2016-07-22T12:07:28.5435467Z
</Message>
<HeaderName>Content-Length</HeaderName>
<HeaderValue>-1</HeaderValue>
</Error>
<小时/>

通过wireshark,我们确保内容长度 header 的值被正确发送。

以下是从wireshark捕获的 header

<小时/>
PUT /test/DC70439C-5004-11E6-B4B2-91D87435845D HTTP/1.1
Host: mytest.blob.core.windows.net
Accept: */*
Transfer-Encoding: chunked
x-ms-blob-type:BlockBlob
x-ms-version:2015-02-21
Content-Length:0
x-ms-date:Fri, 22 Jul 2016 12:07:28 GMT
Authorization:SharedKey kanchan:HQQ7a47TPQtEhL0ek6rim64ZKC8NRubgKuq+4Os+Aoo=
Expect: 100-continue
<小时/>

您能帮忙找出为什么内容长度 header 值被设置为-1吗?

谢谢和问候,拉胡尔·奈克

最佳答案

我没有重现您的问题。以下是我使用 cURL 将文件上传到 Azure blob 存储的测试代码。它在我这边工作,我可以上传大小为0的文件(将文件内容设置为“”)。希望这能给您一些提示。

storage_account="<account name>"
container_name="<container name>"
access_key="<account key>"
content="<file content>"
len=${#content}
blobname="<blob name>"
blob_store_url="blob.core.windows.net"
authorization="SharedKey"
request_method="PUT"
request_date=$(TZ=GMT date "+%a, %d %h %Y %H:%M:%S %Z")
storage_service_version="2011-08-18"
# HTTP Request headers
x_ms_date_h="x-ms-date:$request_date"
x_ms_version_h="x-ms-version:$storage_service_version"
# Build the signature string
canonicalized_headers="x-ms-blob-type:BlockBlob\n${x_ms_date_h}\n${x_ms_version_h}"
canonicalized_resource="/${storage_account}/${container_name}/${blobname}"
string_to_sign="${request_method}\n\n\n${len}\n\napplication/x-www-form-urlencoded\n\n\n\n\n\n\n${canonicalized_headers}\n${canonicalized_resource}"
# Decode the Base64 encoded access key, convert to Hex.
decoded_hex_key="$(echo -n $access_key | base64 -d -w0 | xxd -p -c256)"
signature=$(printf "$string_to_sign" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$decoded_hex_key" -binary | base64 -w0)
authorization_header="Authorization: $authorization $storage_account:$signature"


curl \
-X PUT \
-H "$x_ms_date_h" \
-H "$x_ms_version_h" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "$authorization_header" \
-H "x-ms-blob-type:BlockBlob" \
-d ${content} "https://${storage_account}.${blob_store_url}/${container_name}/${blobname}"

关于Azure Blob 存储 : Unable to upload the blob with size 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38526438/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com