For AI agents: the complete documentation index is available at https://navios.tech/llms.txt, the full documentation bundle is available at https://navios.tech/llms-full.txt, and this page is available as Markdown at https://navios.tech/docs/builder/guides/file-uploads.md.

File uploads

To send files, declare the endpoint with body: 'multipart'. You still pass a plain object as data; Builder validates it and converts it to FormData.

Declaring an upload

export const uploadAvatar = API.declareEndpoint({
  method: 'POST',
  url: '/users/$userId/avatar',
  body: 'multipart',
  requestSchema: z.object({
    file: z.instanceof(File),
    caption: z.string().optional(),
  }),
  responseSchema: z.object({ url: z.string() }),
})

await uploadAvatar({
  urlParams: { userId: '42' },
  data: { file, caption: 'Profile picture' },
})

Everything else about the endpoint works as usual: URL and query parameters, errorSchema, .safe(), and a JSON response validated by responseSchema. As everywhere, the fields are built from what you pass, not from what the schema made of it.

How values become form fields

Each key of data becomes one or more fields:

ValueSent as
Filea file part, with its name
Bloba binary part
arrayone field per item, all under the same key
Datean ISO string
string, number, boolean, bigintits string form
other objectJSON
nullan empty string
undefinedleft out

Form fields are text, but the schema does not have to be. A Navios server decodes each field with the schema's JSON Schema before it validates: z.number(), z.boolean(), objects and arrays, also of one item, can be used as they are. That needs a schema library that implements Standard JSON Schema, as Zod 4 does; Valibot does not by itself, so there describe the text. Never use z.coerce.boolean(), which turns "false" into true.

Several files under one key are an array:

export const uploadAttachments = API.declareEndpoint({
  method: 'POST',
  url: '/posts/$postId/attachments',
  body: 'multipart',
  requestSchema: z.object({
    files: z.array(z.instanceof(File)).min(1).max(10),
    tags: z.array(z.string()).optional(),
  }),
  responseSchema: z.object({ ids: z.array(z.string()) }),
})

If you already have a FormData instance, pass it as data and it is sent unchanged. The requestSchema then has to accept a FormData value, for example z.instanceof(FormData).

Validating files before they are sent

Because the schema runs before the request, size and type limits in it stop a bad upload without using the network. The call fails with kind request-validation.

const imageSchema = z
  .instanceof(File)
  .refine((file) => file.size <= 5 * 1024 * 1024, 'File must be 5 MB or smaller')
  .refine((file) => file.type.startsWith('image/'), 'File must be an image')
const res = await uploadAvatar.safe({ urlParams: { userId: '42' }, data: { file } })

if (!res.ok && res.error.kind === 'request-validation') {
  showError(res.error.issues[0]?.message)
}

Client-side checks are a convenience for the user. The server must enforce the same limits.

Client requirements

Your HTTP client must send a FormData body as it is and let the runtime set the Content-Type header with its boundary. @navios/http, axios and the fetch wrapper in these docs do. If you wrote your own, make sure it does not JSON.stringify a FormData body or force a JSON content type.

For file inputs and upload state in React, see Uploads and downloads in the React Query docs. Receiving the upload on a Navios server is covered in the server's File uploads guide.