簡體   English   中英

如何使用 python sdk 將 blob 上傳到帶有子目錄的 azure 存儲容器中?

[英]How to upload a blob into azure storage container with sub directories using the python sdk?

我一直在關注這篇文章: 快速入門:使用 Python v12 SDKContainerClient.upload_blob的文檔管理 blob

這是上傳具有此目錄結構的 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())

但我收到以下錯誤。 關於我做錯了什么的任何想法?

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

注意:我也看到了這個問題的答案Microsoft Azure: How to create sub directory in a blob container

如果我使用無效的資源名稱(這是錯誤消息告訴您的內容),我能夠重現此問題。

例如,如果我使用testcontainer作為我的 blob 容器名稱(這是正確的),我可以上傳 blob。

但是,如果我使用testContainer作為我的 blob 容器名稱(這是無效的,請注意大寫的“C”),我會得到與你得到的相同的錯誤。

請檢查 blob 容器的名稱和 blob。 請參閱此鏈接了解 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM