3434 fill_class_and_attribute_ids , get_annotation_classes_name_to_id ,
3535 search_annotation_classes
3636)
37+ from .folders import get_folder_metadata
3738from .images import get_image_metadata , search_images
3839from .project_api import get_project_metadata_bare
3940from .users import get_team_contributor_metadata
@@ -438,7 +439,8 @@ def upload_images_from_folder_to_project(
438439 from_s3_bucket = None ,
439440 exclude_file_patterns = None ,
440441 recursive_subfolders = False ,
441- image_quality_in_editor = None
442+ image_quality_in_editor = None ,
443+ folder = None
442444):
443445 """Uploads all images with given extensions from folder_path to the project.
444446 Sets status of all the uploaded images to set_status if it is not None.
@@ -536,7 +538,7 @@ def upload_images_from_folder_to_project(
536538
537539 return upload_images_to_project (
538540 project , filtered_paths , annotation_status , from_s3_bucket ,
539- image_quality_in_editor
541+ image_quality_in_editor , folder
540542 )
541543
542544
@@ -640,7 +642,7 @@ def get_image_array_to_upload(
640642def __upload_images_to_aws_thread (
641643 res , img_paths , project , annotation_status , prefix , thread_id , chunksize ,
642644 couldnt_upload , uploaded , tried_upload , image_quality_in_editor ,
643- from_s3_bucket
645+ from_s3_bucket , folder_id
644646):
645647 len_img_paths = len (img_paths )
646648 start_index = thread_id * chunksize
@@ -696,7 +698,8 @@ def __upload_images_to_aws_thread(
696698 try :
697699 __create_image (
698700 uploaded_imgs_info [0 ], uploaded_imgs_info [1 ], project ,
699- annotation_status , prefix , uploaded_imgs_info [2 ]
701+ annotation_status , prefix , uploaded_imgs_info [2 ],
702+ folder_id
700703 )
701704 except SABaseException as e :
702705 couldnt_upload [thread_id ] += uploaded_imgs
@@ -708,7 +711,7 @@ def __upload_images_to_aws_thread(
708711 try :
709712 __create_image (
710713 uploaded_imgs_info [0 ], uploaded_imgs_info [1 ], project ,
711- annotation_status , prefix , uploaded_imgs_info [2 ]
714+ annotation_status , prefix , uploaded_imgs_info [2 ], folder_id
712715 )
713716 except SABaseException as e :
714717 couldnt_upload [thread_id ] += uploaded_imgs
@@ -718,7 +721,8 @@ def __upload_images_to_aws_thread(
718721
719722
720723def __create_image (
721- img_names , img_paths , project , annotation_status , remote_dir , sizes
724+ img_names , img_paths , project , annotation_status , remote_dir , sizes ,
725+ folder_id
722726):
723727 if len (img_paths ) == 0 :
724728 return
@@ -733,6 +737,8 @@ def __create_image(
733737 "annotation_status" : annotation_status ,
734738 "meta" : {}
735739 }
740+ if folder_id is not None :
741+ data ["folder_id" ] = folder_id
736742 for img_name , img_path , size in zip (img_names , img_paths , sizes ):
737743 img_name_uuid = Path (img_path ).name
738744 remote_path = remote_dir + f"{ img_name_uuid } "
@@ -747,6 +753,7 @@ def __create_image(
747753 response = _api .send_request (
748754 req_type = 'POST' , path = '/image/ext-create' , json_req = data
749755 )
756+ print (data )
750757 if not response .ok :
751758 raise SABaseException (
752759 response .status_code , "Couldn't ext-create image " + response .text
@@ -758,7 +765,8 @@ def upload_images_to_project(
758765 img_paths ,
759766 annotation_status = "NotStarted" ,
760767 from_s3_bucket = None ,
761- image_quality_in_editor = None
768+ image_quality_in_editor = None ,
769+ folder = None
762770):
763771 """Uploads all images given in list of path objects in img_paths to the project.
764772 Sets status of all the uploaded images to set_status if it is not None.
@@ -794,7 +802,7 @@ def upload_images_to_project(
794802 project
795803 )
796804 team_id , project_id = project ["team_id" ], project ["id" ]
797- existing_images = search_images (project )
805+ existing_images = search_images (project , folder = folder )
798806 duplicate_images = []
799807 for existing_image in existing_images :
800808 i = - 1
@@ -831,6 +839,13 @@ def upload_images_to_project(
831839 raise SABaseException (
832840 response .status_code , "Couldn't get upload token " + response .text
833841 )
842+ if folder is not None :
843+ if not isinstance (folder , dict ):
844+ folder_id = get_folder_metadata (project , folder )
845+ else :
846+ folder_id = folder ["id" ]
847+ else :
848+ folder_id = None
834849 res = response .json ()
835850 prefix = res ['filePath' ]
836851 tqdm_thread = threading .Thread (
@@ -847,7 +862,7 @@ def upload_images_to_project(
847862 args = (
848863 res , img_paths , project , annotation_status , prefix , thread_id ,
849864 chunksize , couldnt_upload , uploaded , tried_upload ,
850- image_quality_in_editor , from_s3_bucket
865+ image_quality_in_editor , from_s3_bucket , folder_id
851866 ),
852867 daemon = True
853868 )
0 commit comments