The Product Search feature is in maintenance mode. For better scalability and the same functionality as Product Search, use the
Vision Warehouse.
Delete a reference image
Stay organized with collections
Save and categorize content based on your preferences.
Delete a reference image.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["# Delete a reference image.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Deleting resources](/vision/product-search/docs/delete-resources)\n\nCode sample\n-----------\n\n### Go\n\n\nTo learn how to install and use the client library for Vision API Product Search, see\n[Vision API Product Search client libraries](/vision/product-search/docs/libraries).\n\n\nFor more information, see the\n[Vision API Product Search Go API\nreference documentation](https://godoc.org/cloud.google.com/go/vision/apiv1).\n\n\nTo authenticate to Vision API Product Search, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tvision \"cloud.google.com/go/vision/apiv1\"\n \t\"cloud.google.com/go/vision/v2/apiv1/visionpb\"\n )\n\n // deleteReferenceImage deletes a reference image from a product.\n func deleteReferenceImage(w io.Writer, projectID string, location string, productID string, referenceImageID string) error {\n \tctx := context.Background()\n \tc, err := vision.NewProductSearchClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"NewProductSearchClient: %w\", err)\n \t}\n \tdefer c.Close()\n\n \treq := &visionpb.https://cloud.google.com/go/docs/reference/cloud.google.com/go/vision/v2/latest/apiv1/visionpb.html#cloud_google_com_go_vision_v2_apiv1_visionpb_DeleteReferenceImageRequest{\n \t\tName: fmt.Sprintf(\"projects/%s/locations/%s/products/%s/referenceImages/%s\", projectID, location, productID, referenceImageID),\n \t}\n\n \tif err = c.DeleteReferenceImage(ctx, req); err != nil {\n \t\treturn fmt.Errorf(\"NewProductSearchClient: %w\", err)\n \t}\n\n \tfmt.Fprintf(w, \"Reference image deleted from product.\\n\")\n\n \treturn nil\n }\n\n### Java\n\n\nTo learn how to install and use the client library for Vision API Product Search, see\n[Vision API Product Search client libraries](/vision/product-search/docs/libraries).\n\n\nFor more information, see the\n[Vision API Product Search Java API\nreference documentation](/java/docs/reference/google-cloud-vision/latest/overview).\n\n\nTo authenticate to Vision API Product Search, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n /**\n * Delete a reference image.\n *\n * @param projectId - Id of the project.\n * @param computeRegion - Region name.\n * @param productId - Id of the product.\n * @param referenceImageId - Id of the image.\n * @throws IOException - on I/O errors.\n */\n public static void deleteReferenceImage(\n String projectId, String computeRegion, String productId, String referenceImageId)\n throws IOException {\n try (ProductSearchClient client = ProductSearchClient.create()) {\n\n // Get the full path of the reference image.\n String formattedName =\n ImageName.format(projectId, computeRegion, productId, referenceImageId);\n // Delete the reference image.\n client.deleteReferenceImage(formattedName);\n System.out.println(\"Reference image deleted from product.\");\n }\n }\n\n### Node.js\n\n\nTo learn how to install and use the client library for Vision API Product Search, see\n[Vision API Product Search client libraries](/vision/product-search/docs/libraries).\n\n\nFor more information, see the\n[Vision API Product Search Node.js API\nreference documentation](https://googleapis.dev/nodejs/vision/latest).\n\n\nTo authenticate to Vision API Product Search, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const vision = require('https://cloud.google.com/nodejs/docs/reference/vision/latest/overview.html');\n\n const client = new vision.https://cloud.google.com/nodejs/docs/reference/vision/latest/overview.html();\n\n async function deleteReferenceImage() {\n /**\n * TODO(developer): Uncomment the following line before running the sample.\n */\n // const projectId = 'Your Google Cloud project Id';\n // const location = 'A compute region name';\n // const productId = 'Id of the product';\n // const referenceImageId = 'Id of the reference image';\n\n const formattedName = client.referenceImagePath(\n projectId,\n location,\n productId,\n referenceImageId\n );\n\n const request = {\n name: formattedName,\n };\n\n await client.deleteReferenceImage(request);\n console.log('Reference image deleted from product.');\n }\n deleteReferenceImage();\n\n### Python\n\n\nTo learn how to install and use the client library for Vision API Product Search, see\n[Vision API Product Search client libraries](/vision/product-search/docs/libraries).\n\n\nFor more information, see the\n[Vision API Product Search Python API\nreference documentation](/python/docs/reference/vision/latest).\n\n\nTo authenticate to Vision API Product Search, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import vision\n\n def delete_reference_image(project_id, location, product_id, reference_image_id):\n \"\"\"Delete a reference image.\n Args:\n project_id: Id of the project.\n location: A compute region name.\n product_id: Id of the product.\n reference_image_id: Id of the reference image.\n \"\"\"\n client = vision.https://cloud.google.com/python/docs/reference/vision/latest/google.cloud.vision_v1.services.product_search.ProductSearchClient.html()\n\n # Get the full path of the reference image.\n reference_image_path = client.https://cloud.google.com/python/docs/reference/vision/latest/google.cloud.vision_v1.services.product_search.ProductSearchClient.html#google_cloud_vision_v1_services_product_search_ProductSearchClient_reference_image_path(\n project=project_id,\n location=location,\n product=product_id,\n reference_image=reference_image_id,\n )\n\n # Delete the reference image.\n client.https://cloud.google.com/python/docs/reference/vision/latest/google.cloud.vision_v1.services.product_search.ProductSearchClient.html#google_cloud_vision_v1_services_product_search_ProductSearchClient_delete_reference_image(name=reference_image_path)\n print(\"Reference image deleted from product.\")\n\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=vision_product_search)."]]