Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Vision
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Text recognition
    • Assessing image quality
    • Image moderation
    • Face detection
    • Base64 encoding
  • Concepts
    • Overview
    • Text recognition
      • Overview
      • Template recognition
      • Supported languages
      • Current version restrictions
    • Image classification
      • Overview
      • Supported models
    • Face detection
    • Quotas and limits
  • Access management
  • Pricing policy
  • API reference
    • Authentication in the API
    • gRPC
      • Обзор
      • VisionService
    • REST
      • Handling errors
      • Troubleshooting
      • Overview
      • Vision
        • Overview
        • batchAnalyze
  • Questions and answers
  1. Step-by-step instructions
  2. Base64 encoding

Encoding a file as Base64

    To pass an image file to the Vision API, convert the file content to text in Base64 format:

    UNIX
    Windows
    PowerShell
    Python
    Node.js
    Java
    Go
    $ base64 -i input.jpg > output.txt
    
    C:> Base64.exe -e input.jpg > output.txt
    
    [Convert]::ToBase64String([IO.File]::ReadAllBytes("./input.jpg")) > output.txt
    
    # Импортируйте библиотеку для кодирования в Base64
    import base64
    
    # Создайте функцию, которая кодирует файл и возвращает результат.
    def encode_file(file):
      file_content = file.read()
      return base64.b64encode(file_content)
    
    // Считайте содержимое файла в память.
    var fs = require('fs');
    var file = fs.readFileSync('/path/to/file');
    
    // Получите содержимое файла в формате Base64.
    var encoded = Buffer.from(file).toString('base64');
    
    // Импортируйте библиотеку для кодирования в Base64.
    import org.apache.commons.codec.binary.Base64;
    
    // Получите содержимое файла в формате Base64.
    byte[] fileData = Base64.encodeBase64(yourFile.getBytes());
    
    import (
        "bufio"
        "encoding/base64"
        "io/ioutil"
        "os"
    )
    
    // Откройте файл
    f, _ := os.Open("/path/to/file")
    
    // Прочитайте содержимое файла.
    reader := bufio.NewReader(f)
    content, _ := ioutil.ReadAll(reader)
    
    // Получите содержимое файла в формате Base64.
    base64.StdEncoding.EncodeToString(content)
    

    Pass the content of the resulting output.txt file in the request body's content property:

    {
        "folderId": "b1gvmob95yysaplct532",
        "analyze_specs": [{
            "content": "iVBORw0KGgo...",
            ...
        }]
    }
    
    Language
    Careers
    Privacy policy
    Terms of use
    © 2021 Yandex.Cloud LLC