<p>这是我的示例代码,对我来说很好。在</p>
<pre><code>import os
from azure.storage.blob import BlockBlobService
root_path = '<your root path>'
dir_name = 'images'
path = f"{root_path}/{dir_name}"
file_names = os.listdir(path)
account_name = '<your account name>'
account_key = '<your account key>'
container_name = '<your container name, such as `test` for me>'
block_blob_service = BlockBlobService(
account_name=account_name,
account_key=account_key
)
for file_name in file_names:
blob_name = f"{dir_name}/{file_name}"
file_path = f"{path}/{file_name}"
block_blob_service.create_blob_from_path(container_name, blob_name, file_path)
</code></pre>
<p>如下图所示的结果是来自<a href="https://azure.microsoft.com/en-us/features/storage-explorer/" rel="nofollow noreferrer">Azure Storage Explorer</a>的屏幕截图。在</p>
<p><a href="https://i.stack.imgur.com/rX0N1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rX0N1.png" alt="enter image description here"/></a></p>
<p>有关Azure Storage SDK For Python的API引用的详细信息,请参阅<a href="https://azure-storage.readthedocs.io/index.html" rel="nofollow noreferrer">https://azure-storage.readthedocs.io/index.html</a>。在</p>
<hr/>
<p>更新:我使用的Python版本是Windows上的python3.7.4,所需的包是<code>azure-storage==0.36.0</code>,您可以从<a href="https://pypi.org/project/azure-storage/" rel="nofollow noreferrer">https://pypi.org/project/azure-storage/</a>找到它。在</p>
<ol>
<li><code>$ virtualenv test</code></li>
<li><code>$ cd test</code></li>
<li><code>$ Scripts\active</code></li>
<li><code>$ pip install azure-storage</code></li>
</ol>
<p>然后,您可以在当前Python虚拟环境中通过<code>python upload_images.py</code>运行我的示例代码。在</p>