dongwuxie7976 2016-05-30 23:52
浏览 50

压缩Firebase中的数据

I have a PHP script that makes a query to a webservice. I want the results of this query to be inserted into a row in a Firebase realtime database. This firebase database is then being monitored for changes by an Android app.

The amount of text per row can often be 800 Kb, so I would like to compress this. Otherwise my app will need to have to download 800 Kb before the OnDataChanged event happens.

What I have done is as follows (in the PHP script)

I accept the 800Kb string form the web service. I then run GZip on it in the PHP script. With the result, I then use Base64_Encode and this is what I insert the result to Firebase.

It seems to work fine, and I seem to get around 90% compression, meaning only 80Kb inserted rather than 800Kb. It is however a "round the houses" way to do this.

Is there a better way to do this? Surely there must be. Is there any way to get Firebase to GZip the string is is sending to my app? After all the app is using the Firebase SDK.

Here is the PHP code that writes to Firebase...

$compressed_gzipjson = gzencode($jsonresponse, 9);

$firebase->set(DEFAULT_PATH . '/' , base64_encode($compressed_gzipjson));

Any advice very welcome indeed.

  • 写回答

1条回答 默认 最新

  • duanqin4238 2016-05-31 01:21
    关注

    That sounds like an incredibly wasteful use of a realtime database. The Firebase Database is a great tool for synchronizing small pieces of structured (JSON) data. It is not an ideal fit for unstructured data and the fact that you're OK gzipping the text means that it's unnecessary to synchronize the structure.

    Why don't you simply store the text in a cheaper file storage mechanism (such as Firebase Storage)? Then store the URL of the file in the Firebase Database and synchronize it to the clients that way.

    评论

报告相同问题?

悬赏问题

  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决