使用 firebase 和 react-native-fetch-blob 库创建 React-Native 应用程序。由于此错误,我无法将图像上传到 firebase java.lang.String com.facebook.react.bridge.ReadableMap.string(java.lang.string) on a null object Reference
。
它还给了我警告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"
}