我尝试使用可恢复上传功能在Google云端存储分区中上传视频。 但我总是有同样的错误:(您的回复标题必须包含标题',u' location')
这是我的代码:
client = _get_storage_client()
bucket = client.bucket(BUCKET_NAME, PROJECT_ID)
blob = bucket.blob(filename)
if 'video' in content_type:
url = blob.create_resumable_upload_session(content_type=content_type, client=client)
stream = io.BytesIO(stream_file.file.read())
upload = ResumableUpload(
upload_url=url,
chunk_size=chunk_size
)
transport = AuthorizedSession(credentials=client._credentials)
# Start using the Resumable Upload
response = upload.initiate(
transport=transport,
content_type=content_type,
stream=stream,
metadata={'name': blob.name}
)
while upload.finished is False:
upload.transmit_next_chunk(transport)
错误出现在upload.initiate()
上答案 0 :(得分:1)
你的问题可能在
url = blob.create_resumable_upload_session(content_type=content_type,
client=client)
检查帖子here,他们使用
# Create a Resumable Upload
url = (
f'https://www.googleapis.com/upload/storage/v1/b/'
f'{bucket.name}/o?uploadType=resumable'
)
答案 1 :(得分:0)
您的问题很可能与授权有关。这里的问题是该行
response = upload.initiate(
transport=transport,
content_type=content_type,
stream=stream,
metadata={'name': blob.name}
)
不包含Google云响应。 如果您进入该语句,我建议您调试该语句
method, url, payload, headers = self._prepare_initiate_request(
stream, metadata, content_type,
total_bytes=total_bytes, stream_final=stream_final)
result = _helpers.http_request(
transport, method, url, data=payload, headers=headers,
retry_strategy=self._retry_strategy)
self._process_initiate_response(result)
return result
如果您检查“结果”变量。它将为您提供HTTP状态代码(403为未授权)。结果的内容将为您提供原因和所需的访问权限。
另一种可能性是通过代理发送您的请求并检查HTTP结果。