FormatterHQ

CSV to Base64

Encode CSV data as Base64 for API attachments, JSON payloads and data: download links, preserving every comma, quote and line break.

Loading tool…
Ready.

How to use the CSV to Base64

  1. Type or paste into the CSV box, or click Sample. You can also drop a file on a box or use its Open file button.
  2. The Base64 box updates live as you type. It works both ways — edit the Base64 side to convert back, or click ⇄ Swap to exchange the sides.
  3. Adjust Alphabet and Wrap lines at 76 chars (MIME) in the options bar above the editors; the result refreshes immediately.
  4. Use Copy or Download on either box to take the result, or Clear to start again.

CSV to Base64 for attachments and APIs

Sending a CSV file through an API usually means turning it into a string first. The CSV to Base64 tool encodes your CSV — pasted or opened as a file — as Base64, keeping quoting and delimiters exactly as they are. An opened file is encoded from its own bytes, so the receiver gets a byte-identical file; pasted text is encoded as UTF-8 with LF line breaks.

Example

Input:

id,name,city
1,Ada,London
2,Linus,Helsinki

Output:

aWQsbmFtZSxjaXR5CjEsQWRhLExvbmRvbgoyLExpbnVzLEhlbHNpbmtp

Where you need Base64 CSV

  • Email APIs. Transactional email services such as SendGrid, Postmark or Amazon SES (raw messages) expect attachment content as Base64, together with a filename and a MIME type such as text/csv.
  • JSON-based import endpoints that accept a file as a string field instead of a multipart upload.
  • Download links without a server. A link with href="data:text/csv;base64,…" and a download="report.csv" attribute lets a browser save generated CSV directly.
  • Test fixtures that embed a sample file in a JSON or YAML test case.

Because the Base64 value contains no commas, quotes or line breaks, it can sit safely inside a JSON string, an XML element or a form field without any further escaping — which is the whole point of encoding a CSV file this way.

A client-side download link

const csv = "id,name\n1,Ada";
const b64 = btoa(csv); // ASCII only; encode UTF-8 first for other text
link.href = "data:text/csv;base64," + b64;
link.download = "report.csv";

For larger files, a Blob with URL.createObjectURL() is more efficient than a data URI, because the browser does not have to hold a long Base64 string in the page.

Excel and character encoding

The CSV is encoded as UTF-8. Excel on Windows sometimes opens UTF-8 CSV files as Windows-1252 and shows “é” instead of “é”, unless the file begins with a UTF-8 byte order mark. If your recipients use Excel and the data contains accented characters, add the BOM when generating the file, or ask them to import it via Data › From Text/CSV and choose UTF-8.

Line endings

RFC 4180 specifies CRLF line endings for CSV, while most tools accept plain LF as well. A CSV opened as a file keeps its own line endings, so the decoded file matches it exactly. Text you type or paste is encoded with LF line breaks, because the editor stores every line break as a line feed. If a strict importer needs CRLF, open the CSV as a file instead of pasting it.

Decode Base64 CSV with Base64 to CSV, or turn the data into JSON with CSV to JSON. Encoding happens in your browser; your data is not uploaded.

Frequently asked questions

How do I attach a CSV file in an email API?
Encode the CSV as Base64 and pass it in the attachment’s content field together with a filename such as report.csv and the type text/csv.
Can I create a CSV download link without a server?
Yes. Use an anchor with href="data:text/csv;base64,…" and a download attribute. The browser saves the decoded CSV as a file.
Why do accented characters look wrong in Excel?
Excel may read UTF-8 CSV as Windows-1252. Adding a UTF-8 byte order mark at the start of the file, or importing with UTF-8 selected, fixes it.
Is the CSV changed during encoding?
Not when you open it as a file: every byte is encoded, including quotes, delimiters and line endings. Pasted text is also kept as it is, except that Windows CRLF line endings are encoded as LF.

Last updated October 3, 2026

Related tools