我正在尝试将 CSV 文件存储在 Cloud Firestore 内的文本字段中。然而,Firestore 正在剥离所有换行符并将整个 CSV 文件存储为一行。 Firestore Data Types documentation除了应该是 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.
- 是否有记录在案的限制?
- 如果确实无法存储换行符,推荐的替代方法是什么? Base64 编码?
更新
代码大致是这样的:
/**** 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);
就在调用 Firestore 之前,我可以看到 order.csvFileText
是一个带有换行符的漂亮 CSV 文件(在 Chrome 调试器中)。当我查看存储在 Firestore 中的值(在 Firebase 控制台中)时,换行符丢失了。
最佳答案
所有进出数据库的数据都按原样保存。您所看到的是 Firebase 控制台显示了一个没有回车的简化数据 View 。如果这对您的用例不利,请 file a feature request .
关于javascript - 在 Firestore 文本字段中存储文本文件删除换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54638042/