Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Vision OCR
  • Getting started
    • All guides
    • Text recognition in images
    • Text recognition from PDF files
    • Handwriting recognition
    • Table recognition
    • Base64 encoding
    • Setting up access with API keys
  • Access management
  • Pricing policy
  • Release notes
  • FAQ
  1. Step-by-step guides
  2. Base64 encoding

Encoding a file as Base64

Written by
Yandex Cloud
Updated at March 3, 2025

The Vision OCR API and OCR API support images in Base64 format. Encode your image or PDF file as Base64:

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
# Import a library for encoding files in Base64.
import base64

# Create a function to encode a file and return the results.
def encode_file(file_path):
  with open(file_path, "rb") as fid:
      file_content = fid.read()
  return base64.b64encode(file_content).decode("utf-8")
// Read the file contents to memory.
var fs = require('fs');
var file = fs.readFileSync('/path/to/file');

// Get the file contents in Base64 format.
var encoded = Buffer.from(file).toString('base64');
// Import a library for encoding files in Base64.
import org.apache.commons.codec.binary.Base64;

// Get the file contents in Base64 format.
byte[] fileData = Base64.encodeBase64(yourFile.getBytes());
import (
    "bufio"
    "encoding/base64"
    "io/ioutil"
    "os"
)

// Open the file.
f, _ := os.Open("/path/to/file")

// Read the file contents.
reader := bufio.NewReader(f)
content, _ := ioutil.ReadAll(reader)

// Get the file contents in Base64 format.
base64.StdEncoding.EncodeToString(content)

In the request body, provide the image or PDF file contents encoded as Base64:

{
    "folderId": "b1gvmob95yys********",
    "analyze_specs": [{
        "content": "iVBORw0KGgo...",
        ...
    }]
}

Where:

  • folderId: ID of any folder for which your account has the ai.vision.user role or higher.
  • content: Base64-encoded image or PDF file contents.

Was the article helpful?

Previous
Table recognition
Next
Setting up access with API keys
Yandex project
© 2025 Yandex.Cloud LLC