【发布时间】:2021-03-10 06:16:50
【问题描述】:
我正在尝试使用 fetch 将图像上传到服务器。但我收到类似 = 网络请求失败的错误。 我的代码有什么问题请帮忙。
这是我的代码
const App = () => {
const [singleFile, setSingleFile] = useState(null);
const uploadImage = async () => {
if (singleFile != null) {
const fileToUpload = singleFile;
const data = new FormData();
data.append("lead_tag_number", "NAS00001");
data.append("upload_pan_card_file", fileToUpload)
let res = await fetch(
'https://nasdigital.tech/Android_API_CI/upload_multipart_data',
{
method: 'post',
headers: {
'Content-Type': 'multipart/form-data;',
},
body : data,
}
)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
};
}
const selectFile = async () => {
let pickerResult = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
// base64: true,
aspect: [4, 3],
})
setSingleFile({ singleFile : pickerResult.uri});
};
</View>
);
};
请忽略这个。我正在尝试使用 fetch 将图像上传到服务器。但我收到类似 = 网络请求失败的错误。 我的代码有什么问题请帮忙。我正在尝试使用 fetch 将图像上传到服务器。但我收到类似 = 网络请求失败的错误。 我的代码有什么问题请帮忙。
【问题讨论】:
标签: react-native multipartform-data multipart