1 回答

TA貢獻(xiàn)1876條經(jīng)驗 獲得超6個贊
編輯
HumaddBrandProduct是一個創(chuàng)建另一個函數(shù)的函數(shù)。因此,當(dāng)您調(diào)用this.props.addBrandProduct(postObj)任何內(nèi)容時,都不會發(fā)送到 firestore,您只需創(chuàng)建一個應(yīng)該調(diào)用的新函數(shù)。
也許你可以出去這個東西并直接調(diào)用 firebase,確保一切正常,然后如果你仍然想使用它,則返回到 redux 方式。我還使其并行化而不是順序化。希望它能有所幫助,當(dāng)它來自任何地方時很難找到真正的問題。
onUploadImages = () => {
let photo = Platform.OS === 'ios'
? this.state.images.map(img => img.uri.replace('file://', ''))
: this.state.images.map(img => img.uri);
Promise.all( photo.map( image => {
const sessionId = new Date().getTime();
const Blob = RNFetchBlob.polyfill.Blob;
//This is kind useless
//const fs = RNFetchBlob.fs;
//This is not used
//window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest;
//This is not adviced
//window.Blob = Blob;
let uploadBlob = null;
let mime = 'image/jpg';
const imageRef = firebase
.storage()
.ref('brandProducts/')
.child(`${this.props.userData.uid}`)
.child(`${sessionId}-${i}`);
return fs.readFile(image, 'base64')
.then(data => {
return RNFetchBlob.polyfill.Blob.build(data, {type: `${mime};BASE64`});
})
.then(blob => {
uploadBlob = blob;
return imageRef.put(blob, {contentType: mime});
})
.then(() => {
uploadBlob.close();
return imageRef.getDownloadURL();
});
))
.then( results => {
//results is, here, [ urlFromFirst, urlFronSecond, ...]
const urls = { ...this.state.urls};
results.forEach( (r, i) => urls[i] = r );
const postObj = {
...this.state.postObj,
urls
};
return firebase
.firestore()
.collection('brandProducts')
.add(postObj)
})
.then( docRef => {
console.log("Document written with ID: ", docRef.id);
})
.catch(error => {
console.error(error);
});
};
添加回答
舉報