【发布时间】:2020-01-25 09:18:34
【问题描述】:
我正在尝试将图像上传到 react-native 项目中的 firebase 存储,然后在上传完成后返回下载 URL。
这是我尝试过的: 编辑:
const uploadImg = async (dispatch, uri, uid, mime = 'image/png') => {
console.log('Starting image upload...');
dispatch({ type: types.UPLOAD_IMG, info: 'Uploading profile image...' });
const uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri;
return (imageRef = firebase
.storage()
.ref(uid)
.child('profileImg')
.putFile(uploadUri, { contentType: 'image/png' })
.catch((err) => {
uploadImgFail(dispatch, err.message);
}));
};
部分实现:
uploadImg(dispatch, img, userCredential.user.uid)
.then((imgRef) => {
const imgUrl = imgRef.getDownloadURL();
console.log('uploaded Image URL: ' + imgUrl)
uploadImgSuccess(dispatch, 'Profile image upload successful...');
// rest of action
}
问题是函数未返回下载 URL,我收到未处理的承诺拒绝:“找不到变量:imgUrl”
使用react-native-firebase 可以帮助您实现这一目标吗?
【问题讨论】:
标签: javascript google-cloud-storage react-native-firebase