0

I would like to send a CSV file via POST in a XMLHttpRequest, but I am unsure of two things. First is there anything to distinguish a CSV file from a string split up by comma's? And what sort of Content-Type am I supposed to put in to the setRequestHeader?

1 Answer 1

3

A CSV is, well, a string separated by commas. Trying to separate if there is meaningful data in string as CSV as opposed to A CSV is, well, a string separated by commas is the job for a parser and part of the reason richer data formats (XML, JSON) are often used.

This gets even more fun when you have different flavors of CSV format (line endings, header row, jagged array, muli-line strings in a single field, how to handle a ", etc...). All of these things make CSV difficult to work with as there is no standard.

The closet thing to a standard would be RFC 4180 (this also specifies the mime type as text/csv which is the other part of your question).

1
  • 1
    To phrase your central point differently: any data is a string separated by commas. By themselves, bytes have no meaning – they always have to be interpreted. Metadata like HTTP headers serve to communicate a certain interpretation, as it cannot be part of the data itself.
    – amon
    Commented Mar 16, 2014 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.