【发布时间】:2018-12-25 02:28:42
【问题描述】:
使用 firebase 和 react-native-fetch-blob 库创建 React-Native 应用程序。由于此错误java.lang.String com.facebook.react.bridge.ReadableMap.string(java.lang.string) on a null object Reference,我无法将图像上传到 Firebase。
它还给了我possible unhandled promise Rejection (id=0) 的警告:未定义类型不是函数(评估'filepath.replace('file://,")')
尝试react-native-fetch-blob库的这段代码:
function uploadImage() {
return new Promise((resolve, reject) => {
let imgUri = 'content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F80/ORIGINAL/NONE/1685675380'; let uploadBlob = null;
const uploadUri = imgUri;
const imageRef = firebase.storage().ref();
const name = 'myimg';
mime = 'image/jpeg';
fs.readFile(uploadUri, 'base64')
.then(data => {
return Blob.build(data, { type: `${mime};BASE64` });
})
.then(blob => {
uploadBlob = blob;
return imageRef.put(blob, { contentType: mime, name: name });
})
.then(() => {
uploadBlob.close()
return imageRef.getDownloadURL();
})
.then(url => {
resolve(url);
})
.catch(error => {
reject(error)
})
})
}
dependencies": {
"fbjs": "^0.8.16",
"react": "^16.3.1",
"react-native": "^0.55.3",
"react-native-firebase": "^4.1.0",
"react-native-image-picker": "^0.26.10",
"react-navigation": "^2.6.0",
"rn-fetch-blob": "^0.10.11"
}
【问题讨论】:
标签: firebase react-native react-native-android firebase-storage react-native-fetch-blob