尝试将阻止列表提交到存储帐户时出现无效的阻止列表

问题描述 投票:0回答:1

我一周前来为客户修复一个错误。作为一项日常任务,他们翻译一堆文件并将它们作为块 blob 上传到我们的存储帐户。在这里,我们获取阻止列表,并在提交之前附加新的更改。大约 20 天前,此任务停止工作,他们在尝试提交阻止列表时收到“无效的阻止列表”错误。查看阻止列表,我注意到 ID 与通常的格式发生了变化(它们曾经是 b64 编码的日期,现在是 b64 编码的 uuids)。他们关于此任务的代码库大约一年来没有改变。我尝试将软件包更新到最新版本,但出现同样的错误。

作为检查我们端是否有问题的一种方法,我在开发中完全清除了阻止列表,并且它再次工作了(id 现在每次更改都具有相同的格式),遗憾的是我们不能在生产中执行此操作,因为我们会丢失大量数据。我知道当多个应用程序尝试同时提交时通常会出现此错误,但我们确认这里不是这种情况。

那么造成这种情况的原因可能是什么呢?最近是否对 Azure 存储帐户进行了任何更改或存在其他外部因素?或者问题应该出在我的客户端的某个地方?

任何信息将不胜感激。

python azure azure-blob-storage azure-storage-account
1个回答
0
投票

提交块列表操作通过指定构成 blob 的块 ID 列表来写入 blob。

当组成 Blob 的所有块都已暂存时,您可以将它们提交到 Blob 存储。 使用以下方法创建要作为blob的一部分提交的新块:

  • 使用以下方法通过指定组成 blob 的块 ID 列表来写入 blob:
  • 代码参考取自DOC
import os
import uuid
from azure.storage.blob import BlobServiceClient, BlobBlock

class YourUploaderClass:
    def upload_blocks(self, blob_container_client, local_file_path, block_size):
        try:
            file_name = os.path.basename(local_file_path)
            blob_client = blob_container_client.get_blob_client(file_name)

            with open(file=local_file_path, mode="rb") as file_stream:
                block_id_list = []

                while True:
                    buffer = file_stream.read(block_size)
                    if not buffer:
                        break

                    block_id = uuid.uuid4().hex
                    block_id_list.append(BlobBlock(block_id=block_id))

                    blob_client.stage_block(block_id=block_id, data=buffer, length=len(buffer))

                blob_client.commit_block_list(block_id_list)

            print(f"File '{file_name}' uploaded successfully.")
        except Exception as e:
            print(f"Error uploading file: {str(e)}")

# Example usage
if __name__ == '__main__':
    # Replace <your_connection_string> with your actual connection string
    connection_string = "AzureStorageConnectionString"
    blob_service_client = BlobServiceClient.from_connection_string(connection_string)

    # Replace "your_container_name" with the actual container name
    container_name = "AzureStoragContainerName"

    # Replace "your_local_file_path" with the actual local file path
    local_file_path = "C:/Users/Sequential.html"

    # Replace 40 * 1024 * 1024 with your desired block size
    block_size = 40 * 1024 * 1024

    # Create an instance of the class containing the upload_blocks method
    uploader = YourUploaderClass()

    # Get the container client
    container_client = blob_service_client.get_container_client(container_name)

    # Call the upload_blocks method
    uploader.upload_blocks(container_client, local_file_path, block_size)



enter image description here

蔚蓝: enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.