Developer Toolbox

text/csv

text/csv is the registered type for comma-separated values (RFC 4180). It is text, so it takes a charset; without one, old clients may read UTF-8 as Latin-1 and mangle every accented letter.

Open in cURL Builder A request with this type is filled in.

Header

Content-Type: text/csv; charset=utf-8

At a glance

Extensions
.csv
Kind
Text
Parameters
charset (use utf-8) and header=present or header=absent, which few programs read.
In a browser
Downloads the file. Add Content-Disposition: attachment; filename="report.csv" to choose its name.

With curl

curl -X POST https://api.example.com/import \
  -H 'Content-Type: text/csv; charset=utf-8' \
  --data-binary @people.csv

With fetch

await fetch('https://api.example.com/import', {
  method: 'POST',
  headers: { 'Content-Type': 'text/csv; charset=utf-8' },
  body: file
});

Common mistakes

  • -d strips the line breaks

    curl's -d @file removes carriage returns and newlines, so the rows run together. Send files with --data-binary @file.

  • Excel and the BOM

    Excel opens a UTF-8 CSV correctly only when the file starts with a byte order mark (EF BB BF). Other tools may show it as a stray character in the first header.

  • application/vnd.ms-excel is not CSV

    Some servers send CSV under the Excel type so it opens in Excel. Clients that check the type then refuse it. Send text/csv.