【发布时间】:2021-05-06 07:47:21
【问题描述】:
您好,我编写了一个将图像直接上传到 Azure Blob 存储的爬虫
上传成功,但打开文件时出现错误“无法打开图像文件” 在本地保存时它工作正常,所以在转换为字节上传到 blob 时它会中断。请帮忙
我已尝试根据注释掉的代码将其转换为字符串,但这也不起作用 - 提前非常感谢
block_blob_service = BlockBlobService(account_name=AZURE_ACCOUNT_NAME, account_key=AZURE_ACCOUNT_KEY, connection_string=AZURE_CONNECTION_STRING)
r = requests.get(image_url, stream=True)
image_name='test_thumb.jpg'
output = io.BytesIO()
r.raw.decode_content = True
with Image.open(r.raw) as image:
image.thumbnail((100, 100), Image.ANTIALIAS)
image.save(image_name, format="JPEG")
# thumbnail_as_string = base64.b64encode(output.getvalue())
block_blob_service.create_blob_from_bytes(container_name="media", blob_name=image_name, blob=image.tobytes())```
【问题讨论】:
标签: python python-imaging-library azure-blob-storage django-storage