native-image-picker代码,上传上传的图像时显示问题并显示所选图像,但是当我想将图像保存到数据库中时,它像数据库中的[object Object]一样保存。当我想要获取数据时,图像没有显示。
我在附上我的代码:
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 From 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 {
// You can display the 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 it 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>
)
}
}
当我尝试将图像保存在数据库中时,它会像[object Object]一样保存。可以任何人给我建议如何解决它。非常感谢
答案 0 :(得分:0)
编辑:我指的是对象对象
我想发表评论,但我简短几点。 [object object]表示它是一个对象对象。 javascript中有不同类型的对象。试试JSON.parse(source)