@@ -490,3 +490,76 @@ def get_duplicate_targets(self, target_id: str) -> List[str]:
490490 )
491491
492492 return list (response .json ()['similar_targets' ])
493+
494+ def update_target (
495+ self ,
496+ target_id : str ,
497+ name : Optional [str ] = None ,
498+ width : Optional [Union [int , float ]] = None ,
499+ image : Optional [io .BytesIO ] = None ,
500+ active_flag : Optional [bool ] = None ,
501+ application_metadata : Optional [bytes ] = None ,
502+ ) -> str :
503+ """
504+ Add a target to a Vuforia Web Services database.
505+
506+ See
507+ https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Add-a-Target
508+ for parameter details.
509+
510+ Args:
511+ name: The name of the target.
512+ width: The width of the target.
513+ image: The image of the target.
514+ active_flag: Whether or not the target is active for query.
515+ application_metadata: The application metadata of the target.
516+ This will be base64 encoded.
517+
518+ Returns:
519+ The target ID of the new target.
520+
521+ Raises:
522+ ~vws.exceptions.AuthenticationFailure: The secret key is not
523+ correct.
524+ ~vws.exceptions.BadImage: There is a problem with the given image.
525+ For example, it must be a JPEG or PNG file in the grayscale or
526+ RGB color space.
527+ ~vws.exceptions.Fail: There was an error with the request. For
528+ example, the given access key does not match a known database.
529+ ~vws.exceptions.MetadataTooLarge: The given metadata is too large.
530+ The maximum size is 1 MB of data when Base64 encoded.
531+ ~vws.exceptions.ImageTooLarge: The given image is too large.
532+ ~vws.exceptions.TargetNameExist: A target with the given ``name``
533+ already exists.
534+ ~vws.exceptions.ProjectInactive: The project is inactive.
535+ """
536+ if image is None :
537+ image_data_encoded = None
538+ else :
539+ image_data = image .getvalue ()
540+ image_data_encoded = base64 .b64encode (image_data ).decode ('ascii' )
541+
542+ if application_metadata is None :
543+ metadata_encoded = None
544+ else :
545+ metadata_encoded_str = base64 .b64encode (application_metadata )
546+ metadata_encoded = metadata_encoded_str .decode ('ascii' )
547+
548+ data = {
549+ 'name' : name ,
550+ 'width' : width ,
551+ 'image' : image_data_encoded ,
552+ 'active_flag' : active_flag ,
553+ 'application_metadata' : metadata_encoded ,
554+ }
555+
556+ content = bytes (json .dumps (data ), encoding = 'utf-8' )
557+
558+ response = self ._make_request (
559+ method = 'PUT' ,
560+ content = content ,
561+ request_path = f'/targets/{ target_id } ' ,
562+ expected_result_code = 'Success' ,
563+ )
564+
565+ return str (response .json ()['target_id' ])
0 commit comments