在 SendBird 中上传图片作为新的个人资料图片
Upload image as the new profile image in SendBird
目前正在处理 SendBird 和 react-native 项目,其中模块是关于将自动生成的配置文件图像 profileUrl
更改为从 phone 相机或画廊存储中拍摄的新图像。但是,我输入的以下代码无法正常工作,要么显示错误,要么应用程序冻结。我可以知道我哪里做错了吗? (图像是 uploaded/selected 使用 react-native-image-picker)。
_changeProfileImg(){
ToastAndroid.show('ClickedImage', ToastAndroid.SHORT);
var _Self = this;
var source = [];
ImagePicker.showImagePicker(options, (response) => {
if (response.didCancel){
console.log('user canceled image picker');
}
else if (response.error){
console.log('imagePicker error', response.error);
}
else if (response.customButton){
console.log('customised clicked', response.customButton);
}
else{
source = {uri:response.uri};
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
profileUrl: source,
});
}
});
}
render(){
return(
<View style={styles.container}>
<View style={styles.contentFlex}>
<Text>{this.state.profileUrl}</Text>
<Avatar
rounded
size="xlarge"
source={{uri: this.state.profileUrl}}
onPress={this._changeProfileImg.bind(this)}
activeOpacity={0.7}
/>
</View>
您应该只在 profileUrl
中分配 response.uri
而不是 {uri: response.uri}
,因为您已经指定了 uri
,同时用 profileUrl
在 avatar
.
目前正在处理 SendBird 和 react-native 项目,其中模块是关于将自动生成的配置文件图像 profileUrl
更改为从 phone 相机或画廊存储中拍摄的新图像。但是,我输入的以下代码无法正常工作,要么显示错误,要么应用程序冻结。我可以知道我哪里做错了吗? (图像是 uploaded/selected 使用 react-native-image-picker)。
_changeProfileImg(){
ToastAndroid.show('ClickedImage', ToastAndroid.SHORT);
var _Self = this;
var source = [];
ImagePicker.showImagePicker(options, (response) => {
if (response.didCancel){
console.log('user canceled image picker');
}
else if (response.error){
console.log('imagePicker error', response.error);
}
else if (response.customButton){
console.log('customised clicked', response.customButton);
}
else{
source = {uri:response.uri};
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
profileUrl: source,
});
}
});
}
render(){
return(
<View style={styles.container}>
<View style={styles.contentFlex}>
<Text>{this.state.profileUrl}</Text>
<Avatar
rounded
size="xlarge"
source={{uri: this.state.profileUrl}}
onPress={this._changeProfileImg.bind(this)}
activeOpacity={0.7}
/>
</View>
您应该只在 profileUrl
中分配 response.uri
而不是 {uri: response.uri}
,因为您已经指定了 uri
,同时用 profileUrl
在 avatar
.