如何从Firebase获取要放入数据库的图像的URL路径?

问题描述 投票:0回答:1

如何将我的图像的URL放入数据库?我可以正确地创建这个,但我无法获取URL。我的代码如下:

export  function* createTest(database, storage, action){
    try{
        const {testName, date, image} = action.test

        const ref = yield storage.ref(`images/${testName}`)
        const imagePath = yield new Promise(resolve =>{
            resolve(ref.put(image[0]))
        })
        console.log(imagePath.metadata.downloadURLs[0]) //return undefined
        const id = yield database.ref().child(`some/${action.someId}/tests}`).push().key    
        const newpath = `some/${action.someId}/test/${id}`
        const test = {
            testName,
            imagePath.metadata.downloadURLs[0],
            date
        }
        yield database.ref(newpath).update(test)
        yield put(ActionCreator.createTestSuccess(test))
    }catch({message}){
        yield put(ActionCreator.createTestFailure(message))
    }
    }
javascript reactjs firebase firebase-storage redux-saga
1个回答
0
投票
var ref = storage.ref(`images/${testName}`);

var imageUrl = '';
// Get the download URL
ref.getDownloadURL().then(function(url) {
// Insert url into an <img> tag to "download"
    imageUrl = url;
});
© www.soinside.com 2019 - 2024. All rights reserved.