workers.assets.upload.create() drops per-file Content-Type — assets served with empty MIME type
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 54/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- api
Direzione di ricerca
Inizia da src/uploads.ts, in particolare da addFormValue(), e analizza come workers.assets.upload.create() determina i tipi dei valori del body e li aggiunge. Esamina examples/workers/script-with-assets-upload.ts e la gestione di Uploadable descritta nell’issue. Il lavoro è completato quando i chiamanti di upload possono preservare il tipo MIME di ogni asset e l’esempio non invia più semplici stringhe che producono intestazioni Content-Type vuote.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- TypeScript
- Stelle
- 835
- Fork
- 201
- Merge medio
- 41m
- PR unite (30g)
- 1
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di cloudflare/cloudflare-typescript
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
cloudflare/cloudflare-typescript#2821 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
cloudflare/cloudflare-typescript#2811 ·
-
workers.scripts.deployments.list() paginates the wrong field in v7.2.0Forse già presa @airshakur88 l’ha presa 15 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
cloudflare/cloudflare-typescript#2805 · 1 commento · 1 reazione ·
-
Release CalendarAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
cloudflare/cloudflare-typescript#2755 · 7 commenti · 1 reazione ·
-
<!-- ccr-overview-v2 -->Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 15/100
cloudflare/cloudflare-typescript#2812 ·
Tutte le issue di cloudflare/cloudflare-typescript
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
TriliumNext/Trilium#12837 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
LibreChat-AI/LibreChat#18944 ·
I maintainer di solito rispondono entro 1 giorno
-
bug root-cause:found
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
openchamber/openchamber#7620 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
enhancement good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
Anatomik5/codetovideo#8 ·
-
[Bug] Windows Ghidra provider rejects a PATH-only JDK: bare `java.exe` probe fails with Win32 87Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno