Python 3.x 使用Python将多个文件作为blob上载到Azure存储容器时,上载时间非常慢

Python 3.x 使用Python将多个文件作为blob上载到Azure存储容器时,上载时间非常慢,python-3.x,azure-storage-blobs,azure-container-service,multiple-file-upload,Python 3.x,Azure Storage Blobs,Azure Container Service,Multiple File Upload,我想存储我正在创建的应用程序(我正在使用Azure容器)的反馈部分中的一些用户图像 虽然我能够存储图像,但对于每个190kb的3个文件,该过程大约需要150到200秒 是否有更好的上传文件的方法,或者我在这里遗漏了什么(可能是用于上传的文件类型) 您可以做以下几件事来缩短上载的持续时间: 对所有上传重新使用blob\u服务\u客户端,而不是为每个文件创建一个新的blob\u客户端 用于并行而不是按顺序上载所有文件 如果目标blob父文件夹是静态的,则还可以。这将允许您使用常规的文件系统操作将文件

我想存储我正在创建的应用程序(我正在使用Azure容器)的反馈部分中的一些用户图像

虽然我能够存储图像,但对于每个190kb的3个文件,该过程大约需要150到200秒

是否有更好的上传文件的方法,或者我在这里遗漏了什么(可能是用于上传的文件类型)


您可以做以下几件事来缩短上载的持续时间:

  • 对所有上传重新使用
    blob\u服务\u客户端
    ,而不是为每个文件创建一个新的
    blob\u客户端
  • 用于并行而不是按顺序上载所有文件

  • 如果目标blob父文件夹是静态的,则还可以。这将允许您使用常规的文件系统操作将文件持久化到存储帐户并从中检索文件。

    您可以做一些事情来缩短上载的持续时间:

  • 对所有上传重新使用
    blob\u服务\u客户端
    ,而不是为每个文件创建一个新的
    blob\u客户端
  • 用于并行而不是按顺序上载所有文件
  • 如果目标blob父文件夹是静态的,则还可以。这将允许您使用常规文件系统操作将文件持久化到存储帐户并从中检索文件

    from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient,ContentSettings
    
    
    connect_str = 'my_connection_string'
    
    # Create the BlobServiceClient object which will be used to create a container client
    blob_service_client = BlobServiceClient.from_connection_string(connect_str)
    
    
    photos_object_list = []
    my_content_settings = ContentSettings(content_type='image/png')
    
    #Files to upload
    file_list = ['/Users/vikasnair/Documents/feedbackimages/reference_0.jpg','/Users/vikasnair/Documents/feedbackimages/reference_1.jpeg','/Users/vikasnair/Documents/feedbackimages/reference_2.jpeg']
    
    #creating list of file objects as I would be taking list of file objects from the front end as an input
    for i in range(0,len(file_list)):
        photos_object_list.append(open(file_list[i],'rb'))
    
    import timeit
    start = timeit.default_timer()
    if photos_object_list != None:
        for u in range(0,len(photos_object_list)):
    
            blob_client = blob_service_client.get_blob_client(container="container/folder", blob=loc_id+'_'+str(u)+'.jpg')
    
            blob_client.upload_blob(photos_object_list[u], overwrite=True, content_settings=my_content_settings)
                
    stop = timeit.default_timer()
    
    print('Time: ', stop - start)