workers.assets.upload.create() drops per-file Content-Type — assets served with empty MIME type
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 54/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- typescript
- 領域
- api
調査の方向性
src/uploads.ts、特に addFormValue() から始め、workers.assets.upload.create() が body の値の型をどのように判定して追加するかを調べてください。examples/workers/script-with-assets-upload.ts と、issue に記載されている Uploadable の処理を確認してください。完了の条件は、upload の呼び出し元が各 asset の MIME タイプを保持でき、例が空の Content-Type ヘッダーを生成する単純な文字列を送信しなくなることです。
索引モデルが issue の本文から書いたものです。
説明
Description
client.workers.assets.upload.create() accepts body: Record<string, string> (hash → base64 content). When these plain strings are appended to FormData via addFormValue() in src/uploads.ts, no Content-Type header is set per multipart part.
Per Cloudflare's direct upload docs:
"The provided Content-Type header of each file part will be attached when eventually serving the file."
This means assets uploaded via the SDK are served with an empty MIME type, causing browsers to reject JS module scripts:
Failed to load module script: Expected a JavaScript-or-Wasm module script
but the server responded with a MIME type of "".
Strict MIME type checking is enforced for module scripts per HTML spec.
How wrangler handles this
Wrangler wraps each file in a File object with the correct MIME type before appending to FormData (packages/wrangler/src/assets.ts):
payload.append(
hash,
new File([base64Content], hash, { type: getContentType(absFilePath) ?? "application/null" }),
hash
);
The SDK's addFormValue() in src/uploads.ts already supports Uploadable types (File/Blob) and preserves their .type property. But the typed interface for UploadCreateParams.body is Record<string, string>, making it impossible to pass File objects without casting.
The SDK's own example has this bug
examples/workers/script-with-assets-upload.ts passes plain strings in the body — assets deployed using this example will also be served with empty MIME types.
Reproduction
import Cloudflare from 'cloudflare';
const client = new Cloudflare({ apiToken: '...' });
// Step 1: Create upload session (works fine)
const session = await client.workersForPlatforms.dispatch.namespaces.scripts.assetUpload.create(
namespace, scriptName, { account_id, manifest }
);
// Step 2: Upload assets — THIS DROPS MIME TYPES
for (const bucket of session.buckets) {
const body: Record<string, string> = {};
for (const hash of bucket) {
body[hash] = fileContent.toString('base64');
}
await client.workers.assets.upload.create(
{ account_id, base64: true, body },
{ headers: { Authorization: `Bearer ${session.jwt}` } },
);
}
// Step 3: Deploy worker (works fine)
// ... but all assets are now served with empty Content-Type
Expected behavior
The SDK should either:
- Accept
Record<string, File | Blob | string>for the body parameter, allowing users to pass File objects with MIME types - Or accept a manifest/path mapping so the SDK can infer MIME types from file extensions (like wrangler does)
Workaround
Use raw fetch() with FormData + Blob for the upload step (matching wrangler/vibesdk):
const formData = new FormData();
for (const hash of bucket) {
const blob = new Blob([base64Content], { type: mimeType });
formData.append(hash, blob, hash);
}
await fetch(
`https://api.cloudflare.com/client/v4/accounts/${accountId}/workers/assets/upload?base64=true`,
{ method: 'POST', headers: { Authorization: `Bearer ${jwt}` }, body: formData }
);
Environment
- SDK version:
[email protected] - Runtime: Bun 1.x (also reproducible with Node.js)
- Also affects Workers for Platforms asset uploads via
workersForPlatforms.dispatch.namespaces.scripts.assetUpload
- 主要言語
- TypeScript
- スター
- 835
- フォーク
- 201
- 平均マージ
- 41分
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudflare/cloudflare-typescript のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudflare/cloudflare-typescript#2821 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
cloudflare/cloudflare-typescript#2811 ·
-
workers.scripts.deployments.list() paginates the wrong field in v7.2.0対応中かも @airshakur88 が 15 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
cloudflare/cloudflare-typescript#2805 · コメント 1 件 · リアクション 1 件 ·
-
Release Calendarオープン
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
cloudflare/cloudflare-typescript#2755 · コメント 7 件 · リアクション 1 件 ·
-
難易度 1/5 1〜3時間 初心者へのやさしさ 15/100
cloudflare/cloudflare-typescript#2812 ·
cloudflare/cloudflare-typescript の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
TriliumNext/Trilium#12837 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
LibreChat-AI/LibreChat#18944 ·
メンテナーはふだん 1 日以内に返信
-
bug root-cause:found
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
openchamber/openchamber#7620 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
enhancement good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Anatomik5/codetovideo#8 ·
-
[Bug] Windows Ghidra provider rejects a PATH-only JDK: bare `java.exe` probe fails with Win32 87オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信