ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled photo picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
}
else {
//let source = { uri: response.uri };
// You can also display the image using data:
let source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
ImageSource: source,
data: response.data,
});
}
});
bodyFormData.append('image', {
uri: this.state.ImageSource, // your file path string
name: 'image1.jpg',
type: 'image/jpg'
});
axios({
method: 'post',
url: 'https://',
data: bodyFormData,
config: { headers: { 'Content-Type': 'multipart/form-data' } }
})
答案 0 :(得分:0)
ImagePicker.launchImageLibrary(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };
this.setState({
ImageSource:source,
});
}
});
渲染中的
<Image style={styles.ImageContainer} source={this.state.ImageSource} />
</View>