如何从 Firebase 获取要放入数据库的图像的 URL 路径?
How can I get the URL path of image to put in database from Firebase?
如何将我的图像 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))
}
}
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;
});
如何将我的图像 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))
}
}
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;
});