如何解决在调试模式下,图像和视频未使用axios上传到服务器
我正在使用react-native-image-crop-picker
从图库中获取图像,并尝试使用Axios将其上传到服务器上。但是它没有上传到服务器上,当我点击api进行上传时,它开始发送并且永无休止并没有收到来自服务器的响应。但是,当我尝试进行构建并尝试上传然后成功上传并从服务器获取响应时。
这是我的代码。
const handleProfilePic = () => {
const date = new Date();
const formData = new FormData();
formData.append('files',{
uri: image.path,type: image.mime,name: 'image_' + Math.floor(date.getTime() + date.getSeconds() / 2),});
console.log(formData);
new Promise((rsl,rej) => {
setLoading(true);
updatePic(formData,user.auth,rsl,rej);
})
.then((res) => {
Snackbar.show({
text: res,duration: Snackbar.LENGTH_SHORT,});
setLoading(false);
})
.catch((errorData) => {
setLoading(false);
Snackbar.show({
text: errorData,});
});
};
//add pic code
export const updatePic = (data,token,rej) => {
return (dispatch) => {
axios(`${BASE_URL}/Authentication/addpicture`,{
method: 'post',data,headers: {
auth: token,},})
.then((res) => {
console.log(res);
if (res.data.status == true) {
rsl(res.data.message);
} else {
rej(res.data.message);
}
})
.catch((err) => {
console.log(err);
rej(err.message);
});
};
};
解决方法
我已经通过注释此行解决了它
Open this dir 'android/app/src/debug/java/com/flatApp/ReactNativeFlipper.java'
NetworkingModule.setCustomClientBuilder(
new NetworkingModule.CustomClientBuilder() {
@Override
public void apply(OkHttpClient.Builder builder) {
// builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。