Naresh
Naresh

Reputation: 25773

Storing a text file in Firestore's text field removes line breaks

I am trying to store a CSV file in a text field inside Cloud Firestore. However Firestore is stripping out all line breaks and storing the entire CSV file as a single line. The Firestore Data Types documentation does not say anything about a restriction on the type of characters that can be stored other than they should be UTF-8:

Up to 1,048,487 bytes (1 MiB - 89 bytes). Only the first 1,500 bytes of the UTF-8 representation are considered by queries.

Update

The code roughly looks like this:

/**** Read CSV file ****/
let csvFileText;
const reader = new FileReader();
reader.onload = () => {
    this.setCsvFileText(reader.result);
};
reader.readAsText(file);

//------ Wait for user to hit submit button ------

/**** Create order in Firestore ****/
const order = {
    csvFileText: csvFileText,
    firstName: 'John',
    lastName: 'Doe',
    email: '[email protected]'
}

return this.db
    .collection('orders')
    .add(order)
    .then(docRef => docRef.id);

Just before calling Firestore, I can see that order.csvFileText is a nice CSV file with line breaks (in Chrome debugger). When I look at the value stored in Firestore (in the Firebase console), the line breaks are lost.

Upvotes: 5

Views: 1648

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317392

All data going in to and out of the database is preserved as-is. What you're seeing is the fact that the Firebase console shows a simplified view of the data without carriage returns. If this isn't good for your use case, please file a feature request.

Upvotes: 4

Related Questions