Registry / devops / axios-form-data

axios-form-data

JSON →
library1.1.1jsnpmunverified

Axios interceptor middleware (v1.1.1) that automatically encodes request bodies containing files into multipart/form-data using the `form-data` library. Designed as a drop-in interceptor for Axios, it detects streams, buffers, or Blob objects in the request data and converts them to form-data with a random boundary. Key differentiator: simple integration via `axios.interceptors.request.use(axiosFormData)` without modifying existing Axios calls. Stable release, no active cadence reported.

npm install axios-form-data
INSTALL
IMPORT
SIG · AXIOS-FORM-DATA
A
axios-form-data
devopsjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

axiosFormData
import axiosFormData from 'axios-form-data'
const axiosFormData = require('axios-form-data')
ESM default export only; CommonJS require will work if your environment supports it but the package is ESM-first.
axiosFormData (default)
import axiosFormData from 'axios-form-data'
import { axiosFormData } from 'axios-form-data'
Named import does not exist; only default export.
TypeScript types
import type { AxiosFormDataInterceptor } from 'axios-form-data'
import { AxiosFormDataInterceptor } from 'axios-form-data'
Type import only; the type is not a runtime value.

Demonstrates attaching the axiosFormData interceptor and sending a request with a readable stream that automatically becomes multipart/form-data.

import axios from 'axios'; import axiosFormData from 'axios-form-data'; import { createReadStream } from 'fs'; // Attach interceptor axios.interceptors.request.use(axiosFormData); // Example request with file const response = await axios.request({ method: 'POST', url: 'https://httpbin.org/post', data: { nonfile: 'Non-file value', file: createReadStream('/path/to/somefile'), }, }); console.log(response.data);
Debug
Known issues
deprecatedThe package may not be actively maintained. Last update was 2022-03-07.
fix
Consider using a more actively maintained alternative like 'form-data' directly or Axios's built-in 'FormData' support in newer versions.
affects: <=1.1.1
gotchaThe interceptor does not handle arrays of files or nested objects automatically; it only flattens the top-level data object.
fix
Manually construct FormData for complex structures, or use a library like 'form-data-util'.
affects: >=1.0.0
gotchaThe interceptor modifies the request config object in place, which may cause unexpected behavior if the same config is reused.
fix
Create a new data object or clone the config before passing to the interceptor.
affects: >=1.0.0
gotchaNode.js readable streams that are not at the beginning (e.g., 'fs.createReadStream' after some reads) may cause errors.
fix
Ensure streams are fresh and at offset 0.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: axiosFormData is not a function
Using named import instead of default import.
fix
Use `import axiosFormData from 'axios-form-data'` instead of `import { axiosFormData } from 'axios-form-data'`.
Cannot find module 'axios-form-data'
Package not installed.
fix
Run `npm install axios-form-data`.
Multipart body not sent; data sent as JSON
Interceptor not attached or attached incorrectly (e.g., to wrong Axios instance).
fix
Call `axios.interceptors.request.use(axiosFormData)` on the same Axios instance used for the request.
ReadableStream is not a function
Trying to pass a non-stream object as a file.
fix
Ensure file values are Node.js Readable streams, Buffers, or Blobs.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
form-datarequiredUsed to create multipart/form-data streams
axiosoptionalPeer dependency — the library is an Axios interceptor
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
axios-form-data — npm install axios-form-data · libregistry