Axios Content-Type for Binary Data and ArrayBuffers

When sending binary data or ArrayBuffer instances using Axios, the library determines the HTTP Content-Type header through automatic data-type inspection in its request transformers. Because raw memory buffers lack inherent metadata, Axios identifies the underlying object type at runtime and either falls back to standard binary MIME types like application/octet-stream or relies on explicit user configuration.

Axios Runtime Type Checking

Axios processes outgoing payloads through its default request transformers (transformRequest). During this phase, Axios uses internal utility functions to detect the exact format of the data payload:

Automatic Header Assignment

  1. ArrayBuffer, TypedArrays, and Node Buffers: When raw binary formats such as ArrayBuffer, Uint8Array, or Node.js Buffer are supplied without a predefined header, Axios cannot infer the specific file format (e.g., JPEG, PDF, ZIP) because raw bytes contain no MIME metadata. Axios automatically sets the Content-Type header to application/octet-stream or leaves the transport adapter to handle raw byte streaming.
  2. Blob Objects: Unlike ArrayBuffer, a Blob contains a native type property. If you pass a Blob in the browser and have not manually defined a header, Axios utilizes the Blob.type value to set the Content-Type (for example, image/png). If the Blob.type is empty, it falls back to application/octet-stream.
  3. FormData: When sending binary data inside a FormData container (multipart upload), Axios removes any static Content-Type header to let the browser or adapter automatically generate multipart/form-data along with the appropriate boundary string.

Overriding the Content-Type Manually

Because an ArrayBuffer defaults to application/octet-stream, you must explicitly declare the Content-Type in the request configuration if the receiving server expects a specific MIME type:

import axios from 'axios';

const buffer = new ArrayBuffer(8);

axios.post('https://api.example.com/upload', buffer, {
  headers: {
    'Content-Type': 'application/pdf'
  }
});

When an explicit Content-Type is provided in the configuration object, Axios respects the user definition and overrides its automatic type deduction.