python - 如何将数据流式传输到 python 中的 azure block blob

标签 python azure-blob-storage

我想用 python 将数据流式传输到 azure block blob。下面的代码创建了 blob,但以零字节结束。我怎样才能使它工作?

import io
import struct
from azure.storage.blob import BlockBlobService

storage = BlockBlobService('acct-xxx', 'key-xxx')
stream = io.BytesIO()
storage.create_blob_from_stream("mycontainer", "myblob", stream)
stream.write(struct.pack("d", 12.34))
stream.write(struct.pack("d", 56.78))
stream.close()

最佳答案

看来你错过了关键的代码行:

stream.seek(0)

我将流的 Position 属性 设置为 0,然后您的代码就可以工作了。

import io
import struct
from azure.storage.blob import BlockBlobService

storage = BlockBlobService('acct-xxx', 'key-xxx')
stream = io.BytesIO()

stream.write(struct.pack("d", 12.34))
stream.write(struct.pack("d", 56.78))
stream.seek(0)
storage.create_blob_from_stream("mycontainer", "myblob", stream)
stream.close()

enter image description here

你可以引用这个帖子Azure storage: Uploaded files with size zero bytes .

关于python - 如何将数据流式传输到 python 中的 azure block blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46243969/

相关文章:

javascript - 为什么 diffbot 在这里看不到价格?

python - Python 中的全局变量

azure - 如何确保 blob 文件名在 Azure 存储上是唯一的

azure - 从 Azure 存档存储补充目录

AngularJS adal 对 Azure Blob 存储进行身份验证

javascript - 如何在 asp.net 中使用 javascript 在 Azure BLOB 存储上上传期间压缩视频?

python - 使用 Python C 扩展获取当前工作目录

python - 如何在 python 中获取打开文件的 win32 句柄?

python - 连接时如何避免将整数转换为字符串

azure - Azure 存储数据移动库是否支持 Azure 表?