在react-native中在axios请求中传递图像

问题描述 投票:0回答:1

我正在尝试与此请求一起传递图像,但发送其他参数,但不发送图像。有什么办法会更好。 是我导入的axios实例。 const update = dispatch => async ({ name, email, phone, photo, Age, Blood, Gender, Height, Weight, id }) => { //make api request to update with that info // const picture = new FormData() // picture.append("picture", { // type: 'image/jpg', // uri: photo, // name: 'profilepic.jpg' // }); // const picture = { // type: 'image/jpg', // uri: photo, // name: 'profilepic.jpg' // } // console.log(picture) const picture = { type: 'image/jpg', uri: photo, name: 'profilepic.jpg' } const response = await appApi.put(`/userregister/${id}`, { name, email, phone, picture, Age, Blood, Gender, Height, Weight }) if (response) { console.log(response.data) navigate("AccountScrn"); } else { dispatch({ type: "ADD_ERROR", payload: 'Unable to update profile, please try again later' }) } };

我正在尝试与此请求一起传递图像,但发送其他参数,但不发送图像。有什么办法会更好。 appApi是我导入的axios实例。 const update = dispatch =&...
javascript reactjs react-native axios
1个回答
0
投票
您需要像这样制作FormData
© www.soinside.com 2019 - 2024. All rights reserved.