React native TypeError:尝试在react native中上载图像时,网络请求失败

React native TypeError:尝试在react native中上载图像时,网络请求失败,react-native,React Native,这是我的密码。但是这段代码在模拟器中运行良好,但在设备中不起作用 selectFile = async () => { try { const res = await DocumentPicker.pick({ type: [DocumentPicker.types.images], }); console.log('res : ' + JSON.stringify(re

这是我的密码。但是这段代码在模拟器中运行良好,但在设备中不起作用

selectFile = async () => {
        try {
            const res = await DocumentPicker.pick({
                type: [DocumentPicker.types.images],
            });
            console.log('res : ' + JSON.stringify(res));
            this.setState({ singleFile: res });
            this.uploadImage(res );
        } catch (err) {
            this.setState({ singleFile: null });
            if (DocumentPicker.isCancel(err)) {
                this.setState({ Msg: "Canceled" });
                this.showAlert();
            } else {
                this.setState({ Msg: "Canceled" });
                this.showAlert();
                throw err;
            }
        }
    }


uploadImage(fileToUpload) {
        // Check if any file is selected or not
        AsyncStorage.getItem('usersid', (err, ures) => {
            const baseUrl = b.abc();
            if (this.state.singleFile != null) {
                // If file selected then create FormData
                //const fileToUpload = this.state.singleFile;
                // console.log(fileToUpload.uri, 'nnnnnnnnnnnnnnnnnnn');
                // var photo = {
                //     uri: fileToUpload.uri,
                //     type: fileToUpload.type,
                //     name: fileToUpload.name,
                // };
                console.log(fileToUpload);
                let formBody = new FormData();
                formBody.append('userid', ures);
                formBody.append('profilepic', fileToUpload);
                console.log(formBody);
                // Please change file upload URL
                var url = `${baseUrl}/api/update-profile-pic`;
                fetch(url, {
                    method: 'POST',
                    headers: {
                        //'Accept': 'application/json',
                        'content-type': 'multipart/form-data;',                
                    },
                    body: formBody,
                })
                    .then(response => response.json())
                    .then((res) => {
                        console.log(res);
                        if (res.status === '1' || res.status === 1) {
                            this.setState({ isLoading: false });
                            this.setState({ Msg: res.message });
                            this.showAlert();
                        } else if (res.status === '2' || res.status === 2) {
                            this.setState({ isLoading: false });
                            this.setState({ Msg: res.message });
                            this.showAlert();
                        }
                    }).catch(err => {
                        this.setState({ isLoading: false });
                        alert(err);
                    });
            } else {
                // If no file selected the show alert
                alert('Please Select File first');
            }
        });
    };

这是我的“fileToUpload”控制台-{“name”:“IMG_20200921_165303.jpg”,“type”:“image/jpeg”,“uri”:content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FDCIM%2FCamera%2FIMG_20200921_165303.jpg}

只有在android上出现了相同的问题,添加了
“内容类型”:“应用程序/json”,“连接”:“关闭”
到标题对我有用