Skip to content

Node http adapter drops the filename of FormData files with an empty name, so they arrive as text fields #11331

Open

Description

@Dev-next-gen

Describe the issue

With the Node http adapter, a native FormData file entry whose name is an empty string is serialized without a filename parameter. formDataToStream only writes filename when value.name is truthy, so the part goes out as:

Content-Disposition: form-data; name="upload"
Content-Type: application/octet-stream

Multipart parsers treat a part without filename as a plain text field, so the server receives a string instead of a file, and binary content is decoded as UTF-8. axios's own multipart serializer on the fetch path (formDataToBlob, used when maxBodyLength is set) writes filename="" for the same entry, and its test expects the parsed upload to come back as a file named ''.

Example code

import http from 'http';
import axios from 'axios';

const server = http.createServer((req, res) => {
  const chunks = [];
  req.on('data', (c) => chunks.push(c));
  req.on('end', async () => {
    const form = await new Response(Buffer.concat(chunks), {
      headers: { 'Content-Type': req.headers['content-type'] },
    }).formData();
    console.log(form.get('upload')); // '�\u0000' (a string)
    res.end();
    server.close();
  });
});

server.listen(0, async () => {
  const form = new FormData();
  form.append('upload', new Blob([new Uint8Array([0xff, 0x00])]), '');
  await axios.post(`http://localhost:${server.address().port}/`, form, { adapter: 'http' });
});

Expected behavior

The part carries filename="" and the server gets a File named '' containing the bytes ff 00.

Actual behavior

The part has no filename, the server gets the string '�\u0000', and the 0xff byte is lost.

Environment

  • Axios version: v1.x at 8d415e6 (1.20.0)
  • Adapter: http
  • Runtime: Node 22
  • OS: Linux
  • Additional context: native FormData and Blob

🏄

Activity

  1. added 2 commits that reference this issue on Oct 31, 2026
    fcafc4a
    eab626f
  2. hamarshehmhmd commented on Nov 6, 2026

    @hamarshehmhmd

    Agreed — empty-string filenames should still serialize as filename="", matching formDataToBlob / the fetch path.

    Root cause: lib/helpers/formDataToStream.js uses a truthy check:

    !isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ''

    So name: '' skips the parameter and multipart parsers treat the part as a text field.

    Fix:

    !isStringValue && value.name != null ? `; filename="${escapeName(value.name)}"` : ''

    Verified: added a unit test with name: ''; npm run test:vitest:unit -- tests/unit/helpers/formDataToStream.test.js → all passed (including the new case). Can PR with ai-assisted if useful.

  3. added a commit that references this issue on Nov 19, 2026
    eba31e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions