使用 PutBlock 并将字节数组全部设置为零的 EIPHTTPProtocolExceptionPeer 异常
使用 Delphi XE2 Update 3 我在将零字节块上传到 Azure 时遇到问题。当我说零字节时,我指的是每个元素设置为零的字节数组(不是零长度)。
例如:
var
ConInfo: TAzureConnectionInfo;
RespInfo: TCloudResponseInfo;
BlobService: TAzureBlobService;
Content: TBytes;
MD5: String;
Hasher: TIdHashMessageDigest5;
begin
ConInfo:=TAzureConnectionInfo.Create(self);
ConInfo.AccountName:='YOUR ACCOUNT NAME';
ConInfo.AccountKey:='YOUR ACCOUNT KEY';
ConInfo.Protocol:='http';
BlobService:=TAzureBlobService.Create(ConInfo);
RespInfo:=TCloudResponseInfo.Create;
SetLength(Content, 1048576); // 1 MByte
FillMemory(@Content[0], 1048576, 0); // << --- fill it with anything except 0 and it works
Hasher:=TIdHashMessageDigest5.Create;
MD5:=Data.Cloud.CloudAPI.EncodeBytes64(Hasher.HashBytes(Content));
Hasher.Free;
BlobService.PutBlock('CONTAINER NAME', 'BLOB NAME', MD5, Content, MD5, '', RespInfo);
如果运行上述代码,则调用 PutBlock 时会引发异常:
项目 Project1.exe 引发异常类 EIPHTTPProtocolExceptionPeer 带有消息“HTTP/1.1 403 服务器失败” 对请求进行身份验证。确保授权值 标头格式正确,包括签名。'.
但是,如果您更改 FillMemory 行,使其用 1(或除零以外的任何值)填充,则它可以正常工作而不会出现错误。为什么?
感谢您的任何帮助。
Using Delphi XE2 Update 3 I'm having a problem uploading a block of zero bytes to Azure. When I say zero bytes, I mean an array of bytes with each element set to zero (it's not zero length).
For example:
var
ConInfo: TAzureConnectionInfo;
RespInfo: TCloudResponseInfo;
BlobService: TAzureBlobService;
Content: TBytes;
MD5: String;
Hasher: TIdHashMessageDigest5;
begin
ConInfo:=TAzureConnectionInfo.Create(self);
ConInfo.AccountName:='YOUR ACCOUNT NAME';
ConInfo.AccountKey:='YOUR ACCOUNT KEY';
ConInfo.Protocol:='http';
BlobService:=TAzureBlobService.Create(ConInfo);
RespInfo:=TCloudResponseInfo.Create;
SetLength(Content, 1048576); // 1 MByte
FillMemory(@Content[0], 1048576, 0); // << --- fill it with anything except 0 and it works
Hasher:=TIdHashMessageDigest5.Create;
MD5:=Data.Cloud.CloudAPI.EncodeBytes64(Hasher.HashBytes(Content));
Hasher.Free;
BlobService.PutBlock('CONTAINER NAME', 'BLOB NAME', MD5, Content, MD5, '', RespInfo);
If the above code is run then an exception is raised on the call to PutBlock:
Project Project1.exe raised exception class
EIPHTTPProtocolExceptionPeer with message 'HTTP/1.1 403 Server failed
to authenticate the request. Make sure the value of Authorization
header is formed correctly including the signature.'.
But if you change the FillMemory line so that it fills it with 1's (or anything but zero), then it works without error. Why?
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
令人难以置信的是,问题似乎出在 ttgbNgpWctgMJ0MPORU+LA== 的块 ID 值上,
如果您将其用作块 ID,则会收到该错误。
Unbelievably, it seems that the problem is the block ID value of ttgbNgpWctgMJ0MPORU+LA==
If you use it as a block ID then you get that error.