Upload a file
  1. base64hub
  2. Docs
  3. HTTP API
  4. Encode

POSTEncode

Turn text or bytes into Base64. Standard or URL-safe alphabet, with or without padding, optionally wrapped.

POSThttps://api.base64hub.com/v1/encode

Request

Send JSON with the text in input. The text is encoded as UTF-8.

curl -s https://api.base64hub.com/v1/encode \
  -H 'Content-Type: application/json' \
  -d '{"input": "Hello, hub!"}'

Body parameters

NameTypeDescription
input requiredstringText to encode. It is converted to UTF-8 bytes first.
variant optional"standard" or "url"Alphabet. url uses - and _ instead of + and /. Default "standard".
padding optionalbooleanKeep the trailing =. Default true.
wrap optionalinteger, 0 to 1000Insert \n after every N output characters, none at the end. 76 is MIME. Default 0, no wrapping.

Any other field is rejected with 400 invalid_body.

Raw bytes

To encode a file or any binary data, send the bytes as application/octet-stream. Options then go in the query string: variant=url, padding=false, wrap=76.

printf '\xfb\xff\xbf' | curl -s \
  'https://api.base64hub.com/v1/encode?variant=url&padding=false' \
  -H 'Content-Type: application/octet-stream' \
  --data-binary @-

The body limit is 1 MB. For bigger files use the CLI, which streams.

Response

200 OK · application/json
{
  "output": "SGVsbG8sIGh1YiE=",
  "variant": "standard",
  "padding": true,
  "bytes_in": 11,
  "bytes_out": 16
}
FieldTypeDescription
outputstringThe Base64 text.
variantstringThe alphabet used, standard or url.
paddingbooleanWhether = padding was kept.
bytes_inintegerNumber of input bytes after UTF-8 conversion.
bytes_outintegerLength of output, line breaks included.

With {"input": "foobar", "wrap": 4} the output is "Zm9v\nYmFy" and bytes_out is 9: eight Base64 characters and one line break. The response above is formatted for reading; the API sends it on one line.

Errors

StatusCodeCause
400invalid_bodyNot valid JSON, input missing or not a string, a bad variant, padding or wrap, an unknown field or query parameter, or query options sent with a JSON body.
413too_largeThe body is over 1 MB.
415unsupported_media_typeContent-Type is not application/json or application/octet-stream.
429noneRate limit reached; see limits.

The API overview lists every error.

Updated Nov 22, 2026