Single binary body upload
Use case
Upload a raw file (Blob, File, or ArrayBuffer) as the entire request body, without multipart encoding.
Smallest working example
import { createClient } from '@parcely/core'
const http = createClient({ baseURL: 'https://api.example.com' })
// Blob
const blob = new Blob([arrayBuffer], { type: 'application/zip' })
await http.post('/upload', blob)
// Content-Type is inferred from blob.type
// File (inherits from Blob)
await http.post('/upload', file)
// ArrayBuffer
await http.post('/upload', arrayBuffer, {
headers: { 'Content-Type': 'application/octet-stream' },
})
ReadableStream
You can also pass a ReadableStream directly:
const stream = someReadableStream
await http.post('/upload', stream, {
headers: { 'Content-Type': 'application/octet-stream' },
})
Axios equivalent
In axios, you would pass the binary data as the data argument:
// axios:
await http.post('/upload', blob, {
headers: { 'Content-Type': 'application/zip' },
})
// parcely (identical for Blob/File):
await http.post('/upload', blob)
// Content-Type is inferred from blob.type
Notes and gotchas
Blob,File,ArrayBuffer,ReadableStream, andstringbodies are passed through tofetchwithout modification.- For
BlobandFile,Content-Typeis inferred from the object'stypeproperty. ForArrayBufferandReadableStream, setContent-Typemanually. - Auto-FormData does not trigger for these types -- only for plain objects with File/Blob values.