Cloudflare R2 Uploadのロゴ

Cloudflare R2 Upload

コミュニティ
Innei
cloudflare-r2-upload

Cloudflare R2バケットに1つまたは複数のファイルをアップロードし、紐付けたカスタムドメイン経由で公開URLを返す場合に使います。wrangler CLIとREST API(Cloudflare APIトークン)の方法、一括アップロード、MIMEタイプの処理、複数アカウント環境での適切なアカウント選択、アップロード後の公開URL検証を扱います。「これらの画像をR2にアップロードして」「アセットをuploadsバケットに送って」「R2の<prefix>/配下にファイルを置いて」といったタスクが対象です。

Add to TypingMind

概要

公開者Innei
リポジトリSKILL
スキル名cloudflare-r2-upload
スター
81
フォーク
2
同梱ファイル
指示のみ
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    InneiがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Cloudflare R2 Upload」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/Innei/SKILL/tree/main/skills/infrastructure/cloudflare-r2-upload
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Innei/SKILL.git /tmp/SKILL
mkdir -p .claude/skills
cp -r /tmp/SKILL/skills/infrastructure/cloudflare-r2-upload .claude/skills/cloudflare-r2-upload
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでCloudflare R2 Uploadを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にCloudflare R2 Uploadを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Cloudflare R2 Uploadは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Cloudflare R2 Upload

Use this skill when the task requires pushing local files to a Cloudflare R2 bucket and producing stable public URLs through a bound custom domain (for example object.innei.in).

Scope

  • Target task class: single-file or batched uploads into one R2 bucket under a specified key prefix.
  • Supported auth paths:
    • wrangler CLI with an existing OAuth session.
    • wrangler CLI with CLOUDFLARE_API_TOKEN env (from a Cloudflare API token, e.g. stored as R2_API_KEY).
  • Out of scope: bucket creation, custom-domain binding, CORS / lifecycle config, signed URLs, multipart uploads of files >300 MB.

Inputs

VariableMeaning
R2_API_KEYCloudflare API token with R2 write scope. Optional if wrangler already has an OAuth session.
CLOUDFLARE_ACCOUNT_IDCloudflare account that owns the bucket. Required if the authenticated user belongs to multiple accounts.
BUCKETTarget R2 bucket name (e.g. uploads).
KEY_PREFIXObject key prefix, e.g. mx-space/topics/. Always ends with /.
PUBLIC_DOMAINCustom domain bound to the bucket, e.g. object.innei.in.
SRC_DIRLocal directory containing files to upload.

Workflow

text
[1] Identify account + bucket
      -> wrangler whoami to list accounts
      -> wrangler r2 bucket list (per candidate account) to find BUCKET

[2] Upload each file
      -> wrangler r2 object put BUCKET/KEY --file=PATH --content-type=MIME --remote

[3] Verify via public domain
      -> curl -sI https://PUBLIC_DOMAIN/KEY and assert HTTP 200

[4] Report final URLs
      -> https://PUBLIC_DOMAIN/KEY for each uploaded file

Auth Setup

Prefer an existing wrangler OAuth session — simplest path:

bash
wrangler whoami

If OAuth is unavailable, use an API token instead:

bash
export CLOUDFLARE_API_TOKEN="$R2_API_KEY"

If the user belongs to multiple accounts, always set CLOUDFLARE_ACCOUNT_ID explicitly; otherwise bucket list / object put may default to the wrong account and fail with code: 10042 — Please enable R2 through the Cloudflare Dashboard, which actually means "this account has no R2, try another account".

Finding the Right Account

wrangler whoami prints an account table. For each account id, list buckets until the target bucket is found:

bash
for acct in <id1> <id2> <id3>; do
  echo "=== $acct ==="
  CLOUDFLARE_ACCOUNT_ID="$acct" wrangler r2 bucket list 2>&1 | grep -E "^name:|ERROR" | head -20
done

Cache the resolved CLOUDFLARE_ACCOUNT_ID for the remaining commands.

Single-File Upload

bash
CLOUDFLARE_ACCOUNT_ID="$ACCOUNT_ID" \
  wrangler r2 object put "$BUCKET/${KEY_PREFIX}<name>.webp" \
    --file="/path/to/local.webp" \
    --content-type="image/webp" \
    --remote

Flags that matter:

  • --remote — required. Without it, the write goes to the local simulator, not production.
  • --content-type — set explicitly. Default guessing is unreliable and bad MIME breaks CDN / browsers.
  • Target is a single positional BUCKET/KEY string (no space between bucket and key).

Batch Upload (Directory)

bash
cd "$SRC_DIR" && for f in *.webp; do
  echo "--- $f ---"
  CLOUDFLARE_ACCOUNT_ID="$ACCOUNT_ID" \
    wrangler r2 object put "$BUCKET/${KEY_PREFIX}${f}" \
      --file="$f" \
      --content-type="image/webp" \
      --remote 2>&1 | grep -E 'Creating|error|ERROR' | head -3
done

For mixed MIME types, resolve per-file:

bash
mime_of() {
  case "$1" in
    *.webp) echo "image/webp" ;;
    *.png)  echo "image/png"  ;;
    *.jpg|*.jpeg) echo "image/jpeg" ;;
    *.svg)  echo "image/svg+xml" ;;
    *.json) echo "application/json" ;;
    *.html) echo "text/html; charset=utf-8" ;;
    *.txt|*.md) echo "text/plain; charset=utf-8" ;;
    *)      echo "application/octet-stream" ;;
  esac
}

Verification

Never claim success based on wrangler output alone. Run an HTTP HEAD against the public domain for every uploaded key:

bash
for f in "$SRC_DIR"/*.webp; do
  name=$(basename "$f")
  code=$(curl -sI -o /dev/null -w '%{http_code}' \
    "https://${PUBLIC_DOMAIN}/${KEY_PREFIX}${name}")
  printf "%-40s %s\n" "$name" "$code"
done

All lines must show 200. A 404 means the key path or bucket binding is wrong; a 403 means the custom domain is not bound to this bucket.

Common Mistakes

MistakeSymptomFix
Omitting --remoteUpload "succeeds" but public URL 404sRe-upload with --remote
Wrong accountPlease enable R2 through the Cloudflare Dashboard [code: 10042]Set CLOUDFLARE_ACCOUNT_ID to the account that actually owns the bucket
Missing --content-typeBrowser downloads instead of rendering; image shows as broken in <img>Always pass explicit MIME
Leading slash in keyCreates literal /prefix/... (double slash) pathsEnsure KEY_PREFIX does not start with /
Space in BUCKET/KEYCLI parses as two args, errorsPass as one single unbroken string
npx wrangler fails on pnpm-only setupsERROR Unknown option: 'yes'Use pnpm dlx wrangler@latest instead
Using local wrangler dev stateWrites invisible in production bucketAlways --remote for production writes

Rules

  • Prefer OAuth session over API token when both are available.
  • Always verify at least one URL per batch through the public domain before reporting completion.
  • Do not delete previous-generation objects immediately after updating DB records; keep a rollback window.
  • Never paste R2_API_KEY or CLOUDFLARE_API_TOKEN values into commit logs, commit messages, or PR descriptions.
  • Do not mix --remote and non-remote calls in the same batch.

Reporting Output

Preferred structured summary after a batch:

filesizekeystatus
emo.webp18.3 KBmx-space/topics/emo.webp200
............

Always list the fully-qualified public URLs at the end so the caller can paste them directly into downstream config or DB updates.

よくある質問

AIスキル「Cloudflare R2 Upload」では何ができますか?

Cloudflare R2バケットに1つまたは複数のファイルをアップロードし、紐付けたカスタムドメイン経由で公開URLを返す場合に使います。wrangler CLIとREST API(Cloudflare APIトークン)の方法、一括アップロード、MIMEタイプの処理、複数アカウント環境での適切なアカウント選択、アップロード後の公開URL検証を扱います。「これらの画像をR2にアップロードして」「アセットをuploadsバケットに送って」「R2の<prefix>/配下にファイルを置いて」といったタスクが対象です。

TypingMindでCloudflare R2 Uploadを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Cloudflare R2 Uploadはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにCloudflare R2 Uploadをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/Innei/SKILL/tree/main/skills/infrastructure/cloudflare-r2-uploadを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Cloudflare R2 Uploadを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Cloudflare R2 Uploadで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもCloudflare R2 Uploadを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Cloudflare R2 Upload」は無料ですか?

InneiがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇