Multipart
Use FormData for files and named fields together. This snippet targets this site’s demo endpoint.
import { Http, bare } from "fetchzen";const body = new FormData();body.set("file", new File(["Hello"], "demo.txt"));body.set("name", "Ada");const api = Http.create(`${location.origin}/api/examples/`, { cache: false, secure: false, preset: bare,});console.log(await api.post("multipart/", body));Ready. No request sent.
Fetch does not report upload progress. Wait for the server's receipt to confirm the file arrived.
Result
Choose Run to see the response.
Event log
No events yet.
What to notice
Section titled “What to notice”Do not set Content-Type manually: Fetch supplies the multipart boundary.
The bounded demo returns counts and discards files and fields without storage.
The file limit is 1 MiB; browser Fetch does not report upload progress.
Next: raw file upload or download.