how to save an uploaded image in react-native -
native-image-picker code upload image,what problem when uploading image uploads , show selected image, when want save image in database, saves [object object] in data base. when want to data image not showing.
here attaching my code:
var { stylesheet, view, image, text, touchableopacity, alertios, textinput, scrollview, nativemodules: { uiimagepickermanager } } = react; class profile extends react.component { constructor(props) { super(props); this.state = { avatarsource: this.props.data.data.profilepic, }; } avatartapped() { var options = { title: 'select photo', cancelbuttontitle: 'cancel', takephotobuttontitle: 'take photo', choosefromlibrarybuttontitle: 'choose library', allowsediting: true, returnbase64image: false, returnisvertical: false, quality: 0.8, nodata: true, storageoptions: { skipbackup: true } } uiimagepickermanager.showimagepicker(options, (didcancel, response) => { console.log('response = ', response); if (didcancel) { console.log('user cancelled image picker'); } else { if (response.custombutton) { console.log('user tapped custom button: ', response.custombutton); } else { // can display image using either: //var source = {uri: 'data:image/jpeg;base64,' + response.data, isstatic: true}; // var source = response.uri ; var source = { uri: response.uri.replace('file://', ''), isstatic: true }; console.log("source:" + source); // in console shows[object object] this.setstate({ avatarsource: source }); } } }); } render() { return ( < view style = { styles.right } > < view style = { styles.column } > < touchableopacity onpress = { this.avatartapped.bind(this) } > < view > { this.state.avatarsource == "" ? < image style = { styles.image } source = { { uri: uri, static: true } } /> : < image style = { styles.image } source = { this.state.avatarsource } /> } < /view> < text style = { styles.changetext } > change < /text> < /touchableopacity> < /view> < /view> ) } }
when try save image in database saves [object object].can 1 give me suggestions how resolve it.any appreciated
edit: mean object object want post comment short couple of points. [object object] means object object. there different types of objects in javascript. try json.parse(source)
Comments
Post a Comment