I'm using react-native-image-crop-picker along with react-native-fetch-blob to grab an image from the camera roll and then save it to a Firebase storage bucket.
class CreateForm extends Component {
componentWillMount() {
this.setState({ loading: false });
}
// RNFetchBlob and RNImageCropPicker working together to store an
// image in firebase, and then returning a url for that image.
openImage() {
this.setState({ loading: true });
const Blob = RNFetchBlob.polyfill.Blob;
const fs = RNFetchBlob.fs;
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
window.Blob = Blob
//const uid = "12345"
ImagePicker.openPicker({
width: 300,
height: 300,
cropping: true,
mediaType: 'photo',
}).then(image => {
const imagePath = image.path;
let uploadBlob = null;
const storage = firebase.storage();
const storageRef = storage.ref();
const imageRef = storageRef.child('dp.jpg');
const mime = 'image/jpg';
fs.readFile(imagePath, 'base64')
.then((data) => {
//console.log(data);
return Blob.build(data, { type: `${mime};BASE64` });
})
.then((blob) => {
uploadBlob = blob;
return imageRef.put(blob, { contentType: mime });
})
.then(() => {
uploadBlob.close();
return imageRef.getDownloadURL();
})
Everything works perfectly until this bit of code:
.then((url) => {
console.log(url);
this.props.entryUpdate({ prop: 'image', url });
});
});
}
It logs the url just fine. But when I try to assign this url as a prop named 'image' to the action creator 'entryUpdate', the Firebase realtime database gets an undefined object and throws an error.
Here's the action creator 'entryUpdate':
export const entryUpdate = ({ prop, value }) => {
return {
type: ENTRY_UPDATE,
payload: { prop, value }
};
};
Without the 'image' prop, everything executes correctly. So I know that I'm not giving the action creator the right syntax somehow. The
this.props.entryUpdate({ prop: 'image', url });
line has to be just plain wrong. Any help would be so appreciated!