如何从firebase存储中加快图像加载?

时间:2017-08-09 07:38:57

标签: javascript firebase firebase-storage

从firebase存储加载图片非常慢,我的网页显示图像的时间超过allow read: if true。有没有办法播种图像加载?当给予世界读取权限时,它是否会成熟:service firebase.storage { match /b/test-project-faac7.appspot.com/o { match /{allPaths=**} { allow read: if request.auth != null; allow write: if request.auth != null; } } }

请指导我,从firebase存储上传和下载图像的最佳方法是什么?感谢。

以下是我的存储规则:

 this.storage.ref(item.imgQuestion).getDownloadURL().then(url => {
    item.imgQuestionUrl = url;
 })

获取下载网址的代码:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android" >
            <solid android:color="#FDD400"/>
            <corners android:radius="15dp" />
        </shape>
    </item>
    <item>
        <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
            android:src="@drawable/buy_card_24dp"
            android:gravity="center" />
    </item>
</layer-list>

1 个答案:

答案 0 :(得分:2)

您可以创建一个cloud-function,在upload之后可以压缩图像并替换原始图像。您可以按照此sample获取一些想法。您需要注意storage上传以触发您的功能。