在 adls 中上传到大文件时出现超时错误

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

我需要使用 python 将一个 200 mb 文件上传到 adls

我正在使用官方文档中提供的代码 - https://learn.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-python?tabs=天蓝色广告

调用以下函数进行上传时-

def upload_file_to_directory_bulk():
    try:

        file_system_client = service_client.get_file_system_client(file_system="system")

        directory_client = file_system_client.get_directory_client("my-directory")
        
        file_client = directory_client.get_file_client("uploaded-file.txt")

        local_file = open("C:\\file-to-upload.txt",'r')

        file_contents = local_file.read()

        file_client.upload_data(file_contents, overwrite=True)

    except Exception as e:
      print(e)

适用于小文件

我收到错误 -

('Connection aborted.', timeout('The write operation timed out'))
当我尝试上传更大的文件(如 200 mb)时。

如何解决这个问题?

python azure azure-data-lake
1个回答
0
投票

这肯定和上传速度有关。尝试将超时增加到 60 秒。此外,如果您将文件分成多个块,将为每个块创建一个单独的连接(具有单独的超时)。

file_client.upload_data(file_contents, overwrite=True, timeout=60)

块大小:

file_client.upload_data(file_contents, overwrite=True, timeout=30, chunk_size=25)
© www.soinside.com 2019 - 2024. All rights reserved.