Ressourcen löschen

Sie können die von der API erstellten Ressourcen zu Referenzbildern, Produkten oder Produktgruppen löschen.

Referenzbild löschen

Sie können ein Referenzbild, das einem Produkt zugeordnet ist, löschen.

Befehlszeile

Senden Sie eine DELETE-Anfrage an den folgenden URI, um ein einzelnes Bild zu löschen.

  • Ersetzen Sie project-id durch die ID Ihres Google Cloud Platform-Projekts (GCP).

  • Ersetzen Sie location-id durch eine gültige Standortkennung. Gültige Standortkennungen sind us-west1, us-east1, europe-west1 und asia-east1.

  • Ersetzen Sie product-id durch die ID des Produkts, das mit dem Bild verknüpft ist.

  • Ersetzen Sie image-id durch die ID des Bilds, das gelöscht werden soll.

curl -X DELETE -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products/product-id/referenceImages/image-id

Die Bilder werden zum Löschen markiert, bleiben aber bis zur nächsten Aktualisierung des Index im Produkt vorhanden.

Die tatsächlichen Bilddateien in Google Cloud Storage werden bei diesem Vorgang NICHT gelöscht. Es wird nur der Verweis auf das Bild im Produkt entfernt.

C#

private static int DeleteReferenceImage(DeleteReferenceImageOptions opts)
{
    var client = ProductSearchClient.Create();
    var request = new DeleteReferenceImageRequest
    {
        // Get the full path of the reference image.
        ReferenceImageName = new ReferenceImageName(opts.ProjectID,
                                                    opts.ComputeRegion,
                                                    opts.ProductID,
                                                    opts.ReferenceImageID)
    };

    client.DeleteReferenceImage(request);
    Console.WriteLine("Reference image deleted from product.");
    return 0;
}

Go


import (
	"context"
	"fmt"
	"io"

	vision "cloud.google.com/go/vision/apiv1"
	visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1"
)

// 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)
	}

	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
}

Java

/**
 * 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 =
        ProductSearchClient.formatImageName(
            projectId, computeRegion, productId, referenceImageId);
    // Delete the reference image.
    client.deleteReferenceImage(formattedName);
    System.out.println("Reference image deleted from product.");
  }
}

Node.js


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

const client = new vision.ProductSearchClient();

/**
 * 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(
  projectId,
  location,
  productId,
  referenceImageId
);

const request = {
  name: formattedName,
};

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

PHP

namespace Google\Cloud\Samples\Vision;

use Google\Cloud\Vision\V1\ProductSearchClient;

/**
 * Delete a reference image
 *
 * @param string $projectId Your Google Cloud project ID
 * @param string $location Google Cloud compute region name
 * @param string $productId ID of the product
 * @param string $referenceImageId ID of the reference image
 */
function product_image_delete($projectId, $location, $productId, $referenceImageId)
{
    $client = new ProductSearchClient();

    # get the name of the reference image.
    $referenceImagePath = $client->referenceImageName($projectId, $location, $productId, $referenceImageId);

    # delete the reference image
    $client->deleteReferenceImage($referenceImagePath);
    print('Reference image deleted from product.');

    $client->close();
}

Python

from google.cloud import vision

def delete_reference_image(
        project_id, location, product_id, reference_image_id):
    """Delete a reference image.
    Args:
        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,
        reference_image=reference_image_id)

    # Delete the reference image.
    client.delete_reference_image(name=reference_image_path)
    print('Reference image deleted from product.')

Ruby

require "google/cloud/vision"

def product_search_delete_reference_image(
  project_id = "your-project-id",
  location   = "us-west1",
  product_id = "your-product-id",
  image_id   = "your-image-id"
)
  client = Google::Cloud::Vision::ProductSearch.new

  reference_image_path = client.reference_image_path(
    project_id, location, product_id, image_id
  )

  client.delete_reference_image reference_image_path

  puts "Reference image #{image_id} deleted from product #{product_id}."
end

Produkt löschen

Sie können ein Produkt, das einem bestimmten Projekt zugeordnet ist, löschen.

Wenn Sie ein Produkt löschen, werden auch alle untergeordneten Bilder gelöscht.

Befehlszeile

Senden Sie eine DELETE-Anfrage an den folgenden URI, um ein einzelnes Produkt zu löschen.

  • Ersetzen Sie project-id durch die ID Ihres Google Cloud Platform-Projekts (GCP).

  • Ersetzen Sie location-id durch eine gültige Standortkennung. Gültige Standortkennungen sind us-west1, us-east1, europe-west1 und asia-east1.

  • Ersetzen Sie product-id durch die ID des Produkts, das mit dem Bild verknüpft ist.

curl -X DELETE -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products/product-id

C#

private static int DeleteProduct(DeleteProductOptions opts)
{
    var client = ProductSearchClient.Create();
    var request = new DeleteProductRequest
    {
        // Get the full path of the product.
        ProductName = new ProductName(opts.ProjectID,
                                     opts.ComputeRegion,
                                     opts.ProductID)
    };

    client.DeleteProduct(request);
    Console.WriteLine("Product deleted.");

    return 0;
}

Go


import (
	"context"
	"fmt"
	"io"

	vision "cloud.google.com/go/vision/apiv1"
	visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1"
)

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

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

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

	fmt.Fprintf(w, "Product deleted.\n")

	return nil
}

Java

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

    // Get the full path of the product.
    String formattedName =
        ProductSearchClient.formatProductName(projectId, computeRegion, productId);

    // Delete a product.
    client.deleteProduct(formattedName);
    System.out.println("Product deleted.");
  }
}

Node.js

// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');

// Creates a client
const client = new vision.ProductSearchClient();

/**
 * 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';

// Resource path that represents full path to the product.
const productPath = client.productPath(projectId, location, productId);

await client.deleteProduct({name: productPath});
console.log('Product deleted.');

PHP

namespace Google\Cloud\Samples\Vision;

use Google\Cloud\Vision\V1\ProductSearchClient;

/**
 * Delete the product and all its reference images.
 *
 * @param string $projectId Your Google Cloud project ID
 * @param string $location Google Cloud compute region name
 * @param string $productId ID of the product
 */
function product_delete($projectId, $location, $productId)
{
    $client = new ProductSearchClient();

    # get the name of the product.
    $productPath = $client->productName($projectId, $location, $productId);

    # delete the product
    $client->deleteProduct($productPath);
    print('Product deleted.' . PHP_EOL);

    $client->close();
}

Python

from google.cloud import vision

def delete_product(project_id, location, product_id):
    """Delete the product and all its reference images.
    Args:
        project_id: Id of the project.
        location: A compute region name.
        product_id: Id of the product.
    """
    client = vision.ProductSearchClient()

    # Get the full path of the product.
    product_path = client.product_path(
        project=project_id, location=location, product=product_id)

    # Delete a product.
    client.delete_product(name=product_path)
    print('Product deleted.')

Ruby

require "google/cloud/vision"

def product_search_delete_product(
  project_id = "your-project-id",
  location   = "us-west1",
  product_id = "your-product_id"
)
  client = Google::Cloud::Vision::ProductSearch.new

  product_path = client.product_path project_id, location, product_id

  client.delete_product product_path

  puts "Product #{product_id} deleted."
end

Produktgruppe löschen

Sie können auch eine Produktgruppe löschen.

Eine gelöschte Produktgruppe wird unmittelbar aus den Ergebnissen entfernt. Durch das Löschen einer Produktgruppe werden jedoch nicht die einzelnen Produkte in der Gruppe entfernt, da ein Produkt zu mehreren Gruppen gehören kann. Die Änderung spiegelt sich nicht erst bei der nächsten Indexaktualisierung wider.

Die tatsächlichen Bilddateien in Google Cloud Storage werden bei diesem Vorgang NICHT gelöscht. ReferenceImage-Ressourcen, die von der API erstellt wurden, werden nicht entfernt.

Befehlszeile

Senden Sie eine DELETE-Anfrage an den folgenden URI, um eine Produktgruppe zu löschen.

  • Ersetzen Sie project-id durch die ID Ihres Google Cloud Platform-Projekts (GCP).

  • Ersetzen Sie location-id durch eine gültige Standortkennung. Gültige Standortkennungen sind us-west1, us-east1, europe-west1 und asia-east1.

  • Ersetzen Sie product-set-id durch die ID der Produktgruppe, die mit den Bildern verknüpft ist.

curl -X DELETE -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets/product-set-id

C#

        private static object DeleteProductSet(DeleteProductSetOptions opts)
        {
            var client = ProductSearchClient.Create();
            var request = new DeleteProductSetRequest
            {
                // Get the full path of the product set.
                ProductSetName = new ProductSetName(opts.ProjectID,
                                                    opts.ComputeRegion,
                                                    opts.ProductSetId)
            };

            // Delete the product set.
            client.DeleteProductSet(request);

            Console.WriteLine("Product set deleted.");
            return 0;
        }

Go


import (
	"context"
	"fmt"
	"io"

	vision "cloud.google.com/go/vision/apiv1"
	visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1"
)

// deleteProductSet deletes a product set.
func deleteProductSet(w io.Writer, projectID string, location string, productSetID string) error {
	ctx := context.Background()
	c, err := vision.NewProductSearchClient(ctx)
	if err != nil {
		return fmt.Errorf("NewProductSearchClient: %v", err)
	}

	req := &visionpb.DeleteProductSetRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/productSets/%s", projectID, location, productSetID),
	}

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

	fmt.Fprintf(w, "Product set deleted.\n")

	return nil
}

Java

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

    // Get the full path of the product set.
    String formattedName =
        ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId);
    // Delete the product set.
    client.deleteProductSet(formattedName);
    System.out.println(String.format("Product set deleted"));
  }
}

Node.js

// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');

// Creates a client
const client = new vision.ProductSearchClient();

/**
 * TODO(developer): Uncomment the following line before running the sample.
 */
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
// const productSetId = 'Id of the product set';

// Resource path that represents full path to the product set.
const productSetPath = client.productSetPath(
  projectId,
  location,
  productSetId
);

await client.deleteProductSet({name: productSetPath});
console.log('Product set deleted.');

PHP

namespace Google\Cloud\Samples\Vision;

use Google\Cloud\Vision\V1\ProductSearchClient;

/**
 * Deletes product set
 *
 * @param string $projectId Your Google Cloud project ID
 * @param string $location Google Cloud compute region name
 * @param string $productSetId ID of the product
 */
function product_set_delete($projectId, $location, $productSetId)
{
    $client = new ProductSearchClient();

    # get the name of the product set
    $productSetPath = $client->productSetName($projectId, $location, $productSetId);

    # delete the product set
    $client->deleteProductSet($productSetPath);
    print('Product set deleted.' . PHP_EOL);

    $client->close();
}

Python

from google.cloud import vision

def delete_product_set(project_id, location, product_set_id):
    """Delete a product set.
    Args:
        project_id: Id of the project.
        location: A compute region name.
        product_set_id: Id of the product set.
    """
    client = vision.ProductSearchClient()

    # Get the full path of the product set.
    product_set_path = client.product_set_path(
        project=project_id, location=location,
        product_set=product_set_id)

    # Delete the product set.
    client.delete_product_set(name=product_set_path)
    print('Product set deleted.')

Ruby

require "google/cloud/vision"

def product_search_delete_product_set(
  project_id     = "your-project-id",
  location       = "us-west1",
  product_set_id = "your-product-set-id"
)
  client = Google::Cloud::Vision::ProductSearch.new

  product_set_path = client.product_set_path(
    project_id, location, product_set_id
  )

  client.delete_product_set product_set_path

  puts "Product set #{product_set_id} deleted."
end

Hat Ihnen diese Seite weitergeholfen? Teilen Sie uns Ihr Feedback mit:

Feedback geben zu...

Produktsuche der Cloud Vision API