@@ -821,6 +821,7 @@ def upload_images_to_project(
821821def upload_images_from_public_urls_to_project (
822822 project ,
823823 img_urls ,
824+ img_names = None ,
824825 annotation_status = 'NotStarted' ,
825826 image_quality_in_editor = None
826827):
@@ -831,6 +832,8 @@ def upload_images_from_public_urls_to_project(
831832 :type project: str or dict
832833 :param img_urls: list of str objects to upload
833834 :type img_urls: list
835+ :param img_names: list of str names for each urls in img_url list
836+ :type img_names: list
834837 :param annotation_status: value to set the annotation statuses of the uploaded images NotStarted InProgress QualityCheck Returned Completed Skipped
835838 :type annotation_status: str
836839 :param image_quality_in_editor: image quality be seen in SuperAnnotate web annotation editor.
@@ -840,13 +843,17 @@ def upload_images_from_public_urls_to_project(
840843 :return: uploaded images' urls, uploaded images' filenames, duplicate images' filenames and not-uploaded images' urls
841844 :rtype: tuple of list of strs
842845 """
846+
847+ if img_names is not None and len (img_names ) != len (img_urls ):
848+ raise SABaseException (0 , "Not all image URLs have corresponding names." )
849+
843850 images_not_uploaded = []
844851 images_to_upload = []
845852 duplicate_images_filenames = []
846853 path_to_url = {}
847854 with tempfile .TemporaryDirectory () as save_dir_name :
848855 save_dir = Path (save_dir_name )
849- for img_url in img_urls :
856+ for i , img_url in enumerate ( img_urls ) :
850857 try :
851858 response = requests .get (img_url )
852859 response .raise_for_status ()
@@ -856,12 +863,15 @@ def upload_images_from_public_urls_to_project(
856863 )
857864 images_not_uploaded .append (img_url )
858865 else :
859- if response .headers .get ('Content-Disposition' ) is not None :
860- img_path = save_dir / cgi .parse_header (
861- response .headers ['Content-Disposition' ]
862- )[1 ]['filename' ]
866+ if not img_names :
867+ if response .headers .get ('Content-Disposition' ) is not None :
868+ img_path = save_dir / cgi .parse_header (
869+ response .headers ['Content-Disposition' ]
870+ )[1 ]['filename' ]
871+ else :
872+ img_path = save_dir / basename (urlparse (img_url ).path )
863873 else :
864- img_path = save_dir / basename ( urlparse ( img_url ). path )
874+ img_path = save_dir / img_names [ i ]
865875
866876 if str (img_path ) in path_to_url .keys ():
867877 duplicate_images_filenames .append (basename (img_path ))
0 commit comments