@@ -1052,91 +1052,6 @@ def upload_images_from_azure_blob_to_project(
10521052 )
10531053
10541054
1055- def upload_images_from_azure_blob_to_project (
1056- project ,
1057- container_name ,
1058- folder_path ,
1059- annotation_status = 'NotStarted' ,
1060- image_quality_in_editor = None
1061- ):
1062- """Uploads all images present in folder_path at container_name Azure blob storage to the project.
1063- Sets status of all the uploaded images to set_status if it is not None.
1064-
1065- :param project: project name or metadata of the project to upload images to
1066- :type project: str or dict
1067- :param container_name: container name of the Azure blob storage
1068- :type container_name: str
1069- :param folder_path: path of the folder on the bucket where the images are stored
1070- :type folder_path: str
1071- :param annotation_status: value to set the annotation statuses of the uploaded images NotStarted InProgress QualityCheck Returned Completed Skipped
1072- :type annotation_status: str
1073- :param image_quality_in_editor: image quality be seen in SuperAnnotate web annotation editor.
1074- Can be either "compressed" or "original". If None then the default value in project settings will be used.
1075- :type image_quality_in_editor: str
1076-
1077- :return: uploaded images' urls, uploaded images' filenames, duplicate images' filenames and not-uploaded images' urls
1078- :rtype: tuple of list of strs
1079- """
1080- images_not_uploaded = []
1081- images_to_upload = []
1082- path_to_url = {}
1083- connect_key = os .getenv ('AZURE_STORAGE_CONNECTION_STRING' )
1084- blob_service_client = BlobServiceClient .from_connection_string (connect_key )
1085- container_client = blob_service_client .get_container_client (container_name )
1086- image_blobs = container_client .list_blobs (name_starts_with = folder_path )
1087- with tempfile .TemporaryDirectory () as save_dir_name :
1088- save_dir = Path (save_dir_name )
1089- for image_blob in image_blobs :
1090- content_type = image_blob .content_settings .get ('content_type' )
1091- if content_type is None :
1092- logger .warning (
1093- "Couldn't download image %s, content type could not be verified" ,
1094- image_blob .name
1095- )
1096- continue
1097- if content_type .split ('/' )[0 ] != 'image' :
1098- continue
1099- image_name = basename (image_blob .name )
1100- image_save_pth = save_dir / image_name
1101- try :
1102- image_blob_client = blob_service_client .get_blob_client (
1103- container = container_name , blob = image_blob
1104- )
1105- image_stream = image_blob_client .download_blob ()
1106- except Exception as e :
1107- logger .warning (
1108- "Couldn't download image %s, %s" , image_blob .name , str (e )
1109- )
1110- images_not_uploaded .append (image_blob .name )
1111- else :
1112- with open (image_save_pth , 'wb' ) as image_file :
1113- image_file .write (image_stream .readall ())
1114- path_to_url [str (image_save_pth )] = image_blob .name
1115- images_to_upload .append (image_save_pth )
1116- images_uploaded_paths , images_not_uploaded_paths , duplicate_images_paths = upload_images_to_project (
1117- project ,
1118- images_to_upload ,
1119- annotation_status = annotation_status ,
1120- image_quality_in_editor = image_quality_in_editor
1121- )
1122- images_not_uploaded .extend (
1123- [path_to_url [str (path )] for path in images_not_uploaded_paths ]
1124- )
1125- images_uploaded = [
1126- path_to_url [str (path )] for path in images_uploaded_paths
1127- ]
1128- images_uploaded_filenames = [
1129- basename (path ) for path in images_uploaded_paths
1130- ]
1131- duplicate_images_filenames = [
1132- basename (path ) for path in duplicate_images_paths
1133- ]
1134- return (
1135- images_uploaded , images_uploaded_filenames , duplicate_images_filenames ,
1136- images_not_uploaded
1137- )
1138-
1139-
11401055def __upload_annotations_thread (
11411056 team_id , project_id , project_type , anns_filenames , folder_path ,
11421057 annotation_classes_dict , thread_id , chunksize , num_uploaded , from_s3_bucket ,
0 commit comments