Updated on 2022-02-22 GMT+08:00

Deleting an Image

This section describes how to delete an image using AK/SK authentication.

Replace the AK/SK in the sample code with the actual AK/SK. Set either the url or image parameter in the initialized CelebrityRecognitionReq to specify the information of the image you want to delete. After the configuration is complete, run the code.

  1. The sample code for deleting an image is as follows:
    # coding: utf-8 
    
     
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkimagesearch.v1 import *
    from huaweicloudsdkimagesearch.v1.region.imagesearch_region import ImageSearchRegion
     
    if __name__ == "__main__":
        ak = "<YOUR AK>"
        sk = "<YOUR SK>"
     
        credentials = BasicCredentials(ak, sk)
        client = ImageSearchClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ImageSearchRegion.value_of("cn-north-4")) \
            .build()
     
        try:
            request = RunDeletePictureRequest()
            # Set the instance name.
            request.instance_name="instance-name"
            # Set the image path.
            request.body = DeletePictureReq(
                path="https://bucketname.obs.cn-north-4.myhuaweicloud.com/imagesearch-test.jpg"
            )
            response = client.run_delete_picture(request)
            print(response.status_code)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
  2. Execute the sample code. If the image deletion result is displayed on the console, the code is successfully executed. For details, see Deleting an Image.
    200 
     {
      "result": "success."
     }