Visitar URL original
getHeaders should add content length if known · Issue #534 · form-data/form-data · GitHub
Skip to content

getHeaders should add content length if known #534

Open

Description

@wmertens

If all the form data has known lengths, it would be nice if getHeaders() automatically included the Content-Length header.

Activity

  1. XenoBino commented on Apr 30, 2022

    @XenoBino

    Until it's supported, use:

    const formData = new FormData();
    // ...
    const buffer = formData.getBuffer();
    
    // or axios, or whatever
    fetch(url, {
      headers: {
        ..formData.getHeaders(),
        "Content-Length": buffer.byteLength.toString()
      },
      body: buffer
    })
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