[英]How to upload a blob into azure storage container with sub directories using the python sdk?
I was following along this article: Quickstart: Manage blobs with Python v12 SDK and the documentation for ContainerClient.upload_blob
我一直在关注这篇文章: 快速入门:使用 Python v12 SDK和ContainerClient.upload_blob
的文档管理 blob
Here's the snippet to upload a blob with this directory structure: testcontainer / backup / HelloWorld.cab
这是上传具有此目录结构的 blob 的片段: testcontainer / backup / HelloWorld.cab
bsc = BlobServiceClient.from_connection_string('<connection-string>')
cc = bsc.get_container_client('testcontainer')
cc.upload_blob(name='testcontainer/backup/HelloWorld.cab', data=open(r"\\network\path\to\backup\HelloWorld.cab", 'rb').read())
But I get the following error.但我收到以下错误。 Any ideas on what I'm doing wrong?关于我做错了什么的任何想法?
azure.storage.blob._generated.models._models_py3.StorageErrorException: Operation returned an invalid status 'The specifed resource name contains invalid characters.'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python3\lib\site-packages\azure\core\tracing\decorator.py", line 83, in wrapper_use_tracer
return func(*args, **kwargs)
File "C:\Python3\lib\site-packages\azure\storage\blob\_container_client.py", line 836, in upload_blob
blob.upload_blob(
File "C:\Python3\lib\site-packages\azure\core\tracing\decorator.py", line 83, in wrapper_use_tracer
return func(*args, **kwargs)
File "C:\Python3\lib\site-packages\azure\storage\blob\_blob_client.py", line 496, in upload_blob
return upload_block_blob(**options)
File "C:\Python3\lib\site-packages\azure\storage\blob\_upload_helpers.py", line 153, in upload_block_blob
process_storage_error(error)
File "C:\Python3\lib\site-packages\azure\storage\blob\_shared\response_handlers.py", line 147, in process_storage_error
raise error
azure.core.exceptions.HttpResponseError: The specifed resource name contains invalid characters.
RequestId:71cad76d-801e-0097-8068-1fc9e0000000
Time:2020-05-01T03:28:33.5320153Z
ErrorCode:InvalidResourceName
Error:None
Note: I also saw this answer to this question: Microsoft Azure: How to create sub directory in a blob container注意:我也看到了这个问题的答案: Microsoft Azure: How to create sub directory in a blob container
I am able to reproduce this issue if I use invalid resource name (which is what the error message is telling you).如果我使用无效的资源名称(这是错误消息告诉您的内容),我能够重现此问题。
For example, if I use testcontainer
as my blob container name (which is correct), I am able to upload the blob.例如,如果我使用testcontainer
作为我的 blob 容器名称(这是正确的),我可以上传 blob。
However if I use testContainer
as my blob container name (which is invalid, notice the uppercase "C"), I get the same error as you're getting.但是,如果我使用testContainer
作为我的 blob 容器名称(这是无效的,请注意大写的“C”),我会得到与你得到的相同的错误。
Please check the name of the blob container and the blob.请检查 blob 容器的名称和 blob。 Please see this link for naming convention for blob resources: https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata .请参阅此链接了解 blob 资源的命名约定: https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.