在Firestore的文本字段中存储文本文件可删除换行符 [英] Storing a text file in Firestore's text field removes line breaks

查看:54
本文介绍了在Firestore的文本字段中存储文本文件可删除换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将CS​​V文件存储在Cloud Firestore内的文本字段中.但是,Firestore会删除所有换行符,并将整个CSV文件存储为一行. Firestore数据类型文档没有说明任何限制关于可以存储的字符类型(不是UTF-8):

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:

最多1,048,487字节(1 MiB-89字节).查询只考虑UTF-8表示形式的前1,500个字节.

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控制台中)的值时,换行符丢失了.

    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.

    推荐答案

    所有进出数据库的数据均按原样保留.您所看到的是Firebase控制台显示了简化的数据视图而没有回车的事实.如果这不适合您的用例,请提交功能请求.

    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.

    这篇关于在Firestore的文本字段中存储文本文件可删除换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆