POSTエンコード
テキストやバイト列を Base64 に変換します。標準または URLセーフのアルファベットで、パディングの有無を選べ、折り返しもできます。
POST
https://api.base64hub.com/v1/encodeリクエスト
テキストを input に入れた JSON を送ります。テキストは UTF-8 としてエンコードされます。
curl -s https://api.base64hub.com/v1/encode \
-H 'Content-Type: application/json' \
-d '{"input": "Hello, hub!"}'
const res = await fetch("https://api.base64hub.com/v1/encode", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ input: "Hello, hub!" }),
});
const { output } = await res.json();
console.log(output); // SGVsbG8sIGh1YiE=
import json
import urllib.request
req = urllib.request.Request(
"https://api.base64hub.com/v1/encode",
data=json.dumps({"input": "Hello, hub!"}).encode(),
headers={"Content-Type": "application/json"},
)
with urllib.request.urlopen(req) as res:
print(json.load(res)["output"]) # SGVsbG8sIGh1YiE=
b64 "Hello, hub!"
# SGVsbG8sIGh1YiE=
ボディのパラメーター
| 名前 | 型 | 説明 |
|---|---|---|
input 必須 | string | エンコードするテキスト。最初に UTF-8 のバイト列に変換されます。 |
variant 省略可 | "standard" または "url" | アルファベット。url は + と / の代わりに - と _ を使います。デフォルトは "standard"。 |
padding 省略可 | boolean | 末尾の = を残します。デフォルトは true。 |
wrap 省略可 | integer(0〜1000) | 出力の N 文字ごとに \n を入れ、末尾には入れません。76 は MIME。デフォルトは 0 で、折り返しなし。 |
それ以外のフィールドは 400 invalid_body で拒否されます。
生のバイト列
ファイルなどのバイナリデータをエンコードするには、バイト列を application/octet-stream として送ります。このときオプションはクエリ文字列で指定します(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 @-
const bytes = new Uint8Array([0xfb, 0xff, 0xbf]);
const res = await fetch(
"https://api.base64hub.com/v1/encode?variant=url&padding=false",
{ method: "POST", headers: { "Content-Type": "application/octet-stream" }, body: bytes },
);
console.log((await res.json()).output); // -_-_
import json
import urllib.request
req = urllib.request.Request(
"https://api.base64hub.com/v1/encode?variant=url&padding=false",
data=b"\xfb\xff\xbf",
headers={"Content-Type": "application/octet-stream"},
)
with urllib.request.urlopen(req) as res:
print(json.load(res)["output"]) # -_-_
printf '\xfb\xff\xbf' | b64 --url --no-pad
# -_-_
ボディの上限は 1 MB です。それより大きなファイルには、ストリーム処理する CLI を使ってください。
レスポンス
200 OK · application/json
{
"output": "SGVsbG8sIGh1YiE=",
"variant": "standard",
"padding": true,
"bytes_in": 11,
"bytes_out": 16
}
| フィールド | 型 | 説明 |
|---|---|---|
output | string | Base64 のテキスト。 |
variant | string | 使ったアルファベット。standard または url。 |
padding | boolean | = パディングを残したかどうか。 |
bytes_in | integer | UTF-8 変換後の入力のバイト数。 |
bytes_out | integer | 改行を含めた output の長さ。 |
{"input": "foobar", "wrap": 4} の場合、出力は "Zm9v\nYmFy" で、bytes_out は 9(Base64 の 8 文字と改行 1 つ)です。上のレスポンスは読みやすく整形したもので、API は 1 行で送ります。
エラー
| ステータス | コード | 原因 |
|---|---|---|
| 400 | invalid_body | 不正な JSON、input がないか文字列でない、variant、padding、wrap の値が不正、未知のフィールドやクエリパラメーター、JSON のボディと一緒に送られたクエリのオプション。 |
| 413 | too_large | ボディが 1 MB を超えている。 |
| 415 | unsupported_media_type | Content-Type が application/json でも application/octet-stream でもない。 |
| 429 | なし | レート制限に達した。制限 を参照。 |
すべてのエラーは API の概要 にまとめています。
更新日 2026/11/22