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


import (

	vision ""
	visionpb ""

// deleteReferenceImage deletes a reference image from a product.
func deleteReferenceImage(w io.Writer, projectID string, location string, productID string, referenceImageID string) error {
	ctx := context.Background()
	c, err := vision.NewProductSearchClient(ctx)
	if err != nil {
		return fmt.Errorf("NewProductSearchClient: %v", err)
	defer c.Close()

	req := &visionpb.DeleteReferenceImageRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/products/%s/referenceImages/%s", projectID, location, productID, referenceImageID),

	if err = c.DeleteReferenceImage(ctx, req); err != nil {
		return fmt.Errorf("NewProductSearchClient: %v", err)

	fmt.Fprintf(w, "Reference image deleted from product.\n")

	return nil


 * Delete a reference image.
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @param referenceImageId - Id of the image.
 * @throws IOException - on I/O errors.
public static void deleteReferenceImage(
    String projectId, String computeRegion, String productId, String referenceImageId)
    throws IOException {
  try (ProductSearchClient client = ProductSearchClient.create()) {

    // Get the full path of the reference image.
    String formattedName =
        ImageName.format(projectId, computeRegion, productId, referenceImageId);
    // Delete the reference image.
    System.out.println("Reference image deleted from product.");


const vision = require('@google-cloud/vision');

const client = new vision.ProductSearchClient();

async function deleteReferenceImage() {
   * TODO(developer): Uncomment the following line before running the sample.
  // const projectId = 'Your Google Cloud project Id';
  // const location = 'A compute region name';
  // const productId = 'Id of the product';
  // const referenceImageId = 'Id of the reference image';

  const formattedName = client.referenceImagePath(

  const request = {
    name: formattedName,

  await client.deleteReferenceImage(request);
  console.log('Reference image deleted from product.');


from import vision

def delete_reference_image(
        project_id, location, product_id, reference_image_id):
    """Delete a reference image.
        project_id: Id of the project.
        location: A compute region name.
        product_id: Id of the product.
        reference_image_id: Id of the reference image.
    client = vision.ProductSearchClient()

    # Get the full path of the reference image.
    reference_image_path = client.reference_image_path(
        project=project_id, location=location, product=product_id,

    # Delete the reference image.
    print('Reference image deleted from product.')

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.