问题
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.
- Is there a documented restriction?
- If indeed line breaks can't be stored, what is the recommended alternative? Base64 encoding?
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: 'jdoe@gmail.com'
}
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.
回答1:
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.
来源:https://stackoverflow.com/questions/54638042/storing-a-text-file-in-firestores-text-field-removes-line-breaks