PageBlob upload as one chunk: x-ms-range invalid(PageBlob作为一个区块上载:x-ms-range无效)
本文介绍了PageBlob作为一个区块上载:x-ms-range无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是my previous question的后续问题,我现在正在尝试使用PutPage API将文件作为一个块上传。预留空间的第一部分工作。我在第二个API调用中收到错误,指出x-ms-range
值有问题
import os
import http.client
from urllib.parse import urlparse
sas_uri = '<SAS URI>'
uri = urlparse(sas_uri)
conn = http.client.HTTPSConnection(uri.hostname, port=uri.port, timeout=3000)
file_path = r"C:UsersuserDownloads
pp.Installer.exe"
with open(file_path, 'rb') as reader:
file = reader.read()
file_size = os.stat(file_path).st_size
block_size = file_size
boundary = block_size % 512
if boundary != 0:
block_size = block_size + 512 - boundary
# Reserve a block space
headers = {
'Content-Type': 'application/octet-stream',
'Content-Length': 0,
'x-ms-blob-type': 'PageBlob',
'x-ms-blob-content-length': block_size
}
conn.request('PUT', sas_uri, '', headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
# Upload the file
headers = {
'Content-Type': 'application/octet-stream',
'Content-Length': file_size,
'x-ms-blob-type': 'PageBlob',
'x-ms-page-write': 'update',
'x-ms-range': f'bytes=0-{file_size-1}'
}
conn.request('PUT', sas_uri + '&comp=page', file, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
错误:
<?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:c3c776d3-e01c-00b7-80de-9386a5000000 Time:2021-08-18T03:11:14.5181971Z</Message><HeaderName>x-ms-range</HeaderName><HeaderValue>bytes=0-3991191</HeaderValue></Error>
推荐答案
您的代码失败的原因是您要上载的数据没有与512字节边界对齐。从此link
:
使用PUT Page提交的用于更新操作的每个页面范围 大小可以高达4 MiB。页面的开始和结束范围必须 与512字节边界对齐。如果您尝试上载范围 对于大于4MB的页面,服务返回状态代码413 (请求实体太大)。
请尝试以下代码:
import sys
import os
import http.client
from urllib.parse import urlparse
sas_uri = '<SAS URI here>'
uri = urlparse(sas_uri)
conn = http.client.HTTPConnection(uri.hostname, port=uri.port, timeout=3000)
file_path = r"C:UsersuserDownloads
pp.Installer.exe"
with open(file_path, 'rb') as reader:
file = reader.read()
file_size = os.stat(file_path).st_size
block_size = file_size
boundary = block_size % 512
if boundary != 0:
padarray = b' ' * (512 - boundary)
file = file + padarray
block_size = block_size + 512 - boundary
# Reserve a block space
headers = {
'Content-Type': 'application/octet-stream',
'Content-Length': 0,
'x-ms-blob-type': 'PageBlob',
'x-ms-blob-content-length': block_size
}
conn.request('PUT', sas_uri, '', headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
# Upload the file
headers = {
'Content-Length': block_size,
'x-ms-page-write': 'update',
'Range': f'bytes=0-{block_size-1}'
}
conn.request('PUT', sas_uri + '&comp=page', file, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
这篇关于PageBlob作为一个区块上载:x-ms-range无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:PageBlob作为一个区块上载:x-ms-range无效
猜你喜欢
- pytorch 中的自适应池是如何工作的? 2022-07-12
- 如何将一个类的函数分成多个文件? 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- 沿轴计算直方图 2022-01-01
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01