export const updateUserAvatarResponse = async data => {
const resp = await fetch(config.domain + '/api/users/update/avatar/', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data',
'Authorization': 'Bearer ' + data.access,
},
body: new FormData('avatar', {
type: 'image/jpeg',
uri: data.avatar.uri,
name: 'filename.jpg',
// data: data.avatar,
}),
});
return await resp.json();
};
updateAva = async () => { const options = { title: '选择头像', // noData: false, storageOptions: { //skipBackup: true, path: 'images', }, // multiple: true, //包括Exif:正确,
};
ImagePicker.showImagePicker(options, (response) => {
if (response.uri) {
this.setState({
imageData: response.uri,
data: response
});
this.uploadImage();
}
});
};
uploadImage = async () => {
const access = await getAccessToken();
const resp = await updateUserAvatarResponse({
access: access,
avatar: this.state.data
});
console.log(this.state.data);
console.log(resp);
};
但出现此错误。
holdtom
相关分类