1

我正在尝试将图像发布到 Firebase 实时数据库。到现在为止,我已经成功地做到了,图像可以显示,但只有当我仍然连接应用程序并且尚未重新加载时

我知道原因是因为uri我在数据库上发布的类型如下:

content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F58/ORIGINAL/NONE/image%2Fjpeg/484166561

这是 Redux 操作中添加帖子的代码:

export const addPost = (postImage, date, description, checkin_location) => {
    return async (dispatch, getState) => {
        const token = getState().auth.user.token;
        const userId = getState().auth.user.uid;
            const response = await fetch(
                `https://..../users/${userId}/posts.json?auth=${token}`, {
                    method: 'POST',
                    headers:{
                        'Content-Type': 'application/json'
                    },
                    credentials: 'same-origin',
                    body: JSON.stringify({
                        postImage,
                        date,
                        description,
                        checkin_location,
                    })
                });

            const resData = await response.json();
            console.log(resData);
            if(!response.ok){
                console.log("reponse isn't ok in post action ", response)
            };

            dispatch({
                type: ADD_POST,
                postData:{
                    id: resData.name,
                    ownerId: userId,
                    postImage,
                    date,
                    description,
                    checkin_location
                }
            })
    }
}

我应该怎么做才能实现这一目标?

或者更准确地说,即使我重新加载或通过另一台设备登录,我如何将该uri链接转换为组件可以显示url的类型或至少一种类型Image

我正在使用实时数据库,听说过 Firestore 和 Cloud Functions,但还没有使用过

请帮忙

4

0 回答 0