Die Produktsuche befindet sich im Wartungsmodus. Für eine bessere Skalierbarkeit und dieselben Funktionen wie bei der Produktsuche können Sie das Vision Warehouse verwenden.
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Sie können für die Cloud Vision API Bilddaten bereitstellen. Geben Sie dazu den URI-Pfad zum Bild an oder senden Sie die Bilddaten als Base64-codierten Text.
Befehlszeile verwenden
Innerhalb einer gRPC-Anfrage können Sie die Binärdaten einfach direkt ausschreiben. Bei einer REST-Anfrage müssen Sie jedoch JSON verwenden. JSON ist ein Textformat, das Binärdaten nicht direkt unterstützt, weshalb diese mit der Base64 in Text umgewandelt werden müssen.
Die meisten Entwicklungsumgebungen enthalten ein natives base64-Dienstprogramm, um ein Binärbild als ASCII-Textdaten zu codieren. So codieren Sie eine Datei:
Linux
Codieren Sie die Datei mithilfe des base64-Befehlszeilentools und achten Sie darauf, Zeilenumbrüche mithilfe des Flags -w 0 zu verhindern:
base64 INPUT_FILE -w 0 > OUTPUT_FILE
macOS
Codieren Sie die Datei mit dem base64-Befehlszeilentool:
base64 -i INPUT_FILE -o OUTPUT_FILE
Windows
Codieren Sie die Datei mit dem Tool Base64.exe:
Base64.exe -e INPUT_FILE > OUTPUT_FILE
PowerShell
Codieren Sie die Datei mit der Methode Convert.ToBase64String:
Erstellen Sie eine JSON-Anfragedatei, die die base64-codierten Daten enthält:
JSON
{"requests":[{"image":{"content":"BASE64_ENCODED_DATA"},"features":[{"type":"PRODUCT_SEARCH"}],"imageContext":{"productSearchParams":{"productSet":"projects/PROJECT_ID/locations/LOCATION/productSets/PRODUCT_SET_ID","productCategories":["apparel"],"filter":"style=... AND color=..."}}}]}
Clientbibliotheken verwenden
Binäre Daten mit Texteditoren in Anfragen einzubetten, ist weder wünschenswert noch praktisch. In der Praxis betten Sie base64-codierte Dateien in den Clientcode ein. Alle unterstützten Programmiersprachen haben integrierte Mechanismen für die base64-codierte Inhalte:
Python
# Import the base64 encoding library.importbase64# Pass the image data to an encoding function.defencode_image(image):withopen(image,"rb")asimage_file:encoded_string=base64.b64encode(image_file.read())returnencoded_string
Node.js
// Read the file into memory.varfs=require('fs');varimageFile=fs.readFileSync('/path/to/file');// Convert the image data to a Buffer and base64 encode it.varencoded=Buffer.from(imageFile).toString('base64');
Java
// Import the Base64 encoding library.importorg.apache.commons.codec.binary.Base64;// Encode the image.StringencodedString=Base64.getEncoder().encodeToString(imageFile.getBytes());
Go
import("bufio""encoding/base64""io""os")// Open image file.f,_:=os.Open("image.jpg")// Read entire image into byte slice.reader:=bufio.NewReader(f)content,_:=io.ReadAll(reader)// Encode image as base64.base64.StdEncoding.EncodeToString(content)
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-19 (UTC)."],[],[],null,["# Base64 Encoding\n\nYou can provide image data to the Cloud Vision API by specifying the URI path to\nthe image, or by sending the image data as base64-encoded text.\n\nUsing the command line\n----------------------\n\nWithin a gRPC request, you can simply write binary data out directly;\nhowever, JSON is used when making a REST request. JSON\nis a text format that does not directly support binary data, so you will need to\nconvert such binary data into text using\n[Base64](https://en.wikipedia.org/wiki/Base64) encoding.\n\nMost development environments contain a native `base64` utility to\nencode a binary into ASCII text data. To encode a file: \n\n### Linux\n\nEncode the file using the `base64` command line tool, making sure to\nprevent line-wrapping by using the `-w 0` flag: \n\n```\nbase64 INPUT_FILE -w 0 \u003e OUTPUT_FILE\n```\n\n### macOS\n\nEncode the file using the `base64` command line tool: \n\n```\nbase64 -i INPUT_FILE -o OUTPUT_FILE\n```\n\n### Windows\n\nEncode the file using the `Base64.exe` tool: \n\n```\nBase64.exe -e INPUT_FILE \u003e OUTPUT_FILE\n```\n\n### PowerShell\n\nEncode the file using the `Convert.ToBase64String` method: \n\n```\n[Convert]::ToBase64String([IO.File]::ReadAllBytes(\"./INPUT_FILE\")) \u003e OUTPUT_FILE\n```\n\nCreate a JSON request file, inlining the base64-encoded data: \n\n### JSON\n\n\n```json\n{\n \"requests\": [\n {\n \"image\": {\n \"content\": \"\u003cvar translate=\"no\"\u003eBASE64_ENCODED_DATA\u003c/var\u003e\"\n },\n \"features\": [\n {\n \"type\": \"PRODUCT_SEARCH\"\n }\n ],\n \"imageContext\": {\n \"productSearchParams\": {\n \"productSet\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e/productSets/\u003cvar translate=\"no\"\u003ePRODUCT_SET_ID\u003c/var\u003e\",\n \"productCategories\": [\n \"apparel\"\n ],\n \"filter\": \"style=... AND color=...\"\n }\n }\n }\n ]\n}\n```\n\n\u003cbr /\u003e\n\nUsing client libraries\n----------------------\n\nEmbedding binary data into requests through text editors is neither\ndesirable or practical. In practice, you will be embedding base64 encoded files\nwithin client code. All supported programming languages have built-in mechanisms\nfor base64 encoding content. \n\n### Python\n\n # Import the base64 encoding library.\n import base64\n\n # Pass the image data to an encoding function.\n def encode_image(image):\n with open(image, \"rb\") as image_file:\n encoded_string = base64.b64encode(image_file.read())\n return encoded_string\n\n### Node.js\n\n // Read the file into memory.\n var fs = require('fs');\n var imageFile = fs.readFileSync('/path/to/file');\n\n // Convert the image data to a Buffer and base64 encode it.\n var encoded = Buffer.from(imageFile).toString('base64');\n\n### Java\n\n // Import the Base64 encoding library.\n import org.apache.commons.codec.binary.Base64;\n\n // Encode the image.\n String encodedString = Base64.getEncoder().encodeToString(imageFile.getBytes());\n\n### Go\n\n import (\n \"bufio\"\n \"encoding/base64\"\n \"io\"\n \"os\"\n )\n\n // Open image file.\n f, _ := os.Open(\"image.jpg\")\n\n // Read entire image into byte slice.\n reader := bufio.NewReader(f)\n content, _ := io.ReadAll(reader)\n\n // Encode image as base64.\n base64.StdEncoding.EncodeToString(content)"]]