<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Chewing the Cud (Posts about Gotchas)</title><link>https://jamesaimonetti.com/</link><description></description><atom:link href="https://jamesaimonetti.com/categories/gotchas.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Wed, 26 Mar 2025 20:45:29 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>cURL stripping newlines from your CSV or other file?</title><link>https://jamesaimonetti.com/posts/2012/01/26/curl-stripping-newlines-from-your-csv-or-other-file/</link><dc:creator>James Aimonetti</dc:creator><description>&lt;p&gt;
I'm in the process of writing a REST endpoint for uploading CSVs to
&lt;a href="http://wiki.2600hz.org/display/docs/REST+APIs+%28High-Level+Functionality%29"&gt;Crossbar&lt;/a&gt;
as part of &lt;a href="http://github.com/2600hz/2600hz-platform"&gt;our
communications platform&lt;/a&gt; at &lt;a href="http://2600hz.org"&gt;2600hz&lt;/a&gt;. Not wanting
to invoke the full REST client interface, I generally use
&lt;a href="http://curl.haxx.se/"&gt;cURL&lt;/a&gt; to send the HTTP requests. Today,
however, I had quite the time figuring out why my CSV files were being
stripped of their newline characters. The initial invocation:
&lt;/p&gt;

&lt;pre class="example" id="org25a3b6b"&gt;
$&amp;gt; curl http://localhost:8000/v1/path/to/upload -H "Content-Type: text/csv" -X POST -d @file.csv
&lt;/pre&gt;

&lt;p&gt;
Walking through the code, from where I was processing the CSV down to
the webserver handling the connection itself, looking for who was
stripping the newlines, I determined it was coming in sans-newlines and
decided to check out &lt;a href="http://curl.haxx.se/docs/manpage.html"&gt;cURL's man
pages&lt;/a&gt; for what might be amiss. I quickly found that the
&lt;a href="http://curl.haxx.se/docs/manpage.html#-d"&gt;-d option&lt;/a&gt; was treating the
file as ascii, and although the docs don't explicitly say so, it appears
this option will strip the newlines. The resolution is to use the
&lt;a href="http://curl.haxx.se/docs/manpage.html#--data-binary"&gt;–data-binary
flag&lt;/a&gt; so cURL doesn't touch the file before sending it to the server.
&lt;/p&gt;</description><category>Geekdom</category><category>Gotchas</category><category>Work</category><guid>https://jamesaimonetti.com/posts/2012/01/26/curl-stripping-newlines-from-your-csv-or-other-file/</guid><pubDate>Thu, 26 Jan 2012 19:33:43 GMT</pubDate></item></channel></rss>