react-native - 图像未在 React Native 中上传到 PHP 服务器
问题描述
我正在尝试将图像从 react native 上传到 PHP 服务器。但我无法上传图片。我尝试所有的东西。我没有收到任何错误,警告。没有任何单一的错误。我仍然无法将图像上传到服务器。为什么?????
这是我的代码
onst App = () => {
const [singleFile, setSingleFile] = useState(null);
const uploadImage = async () => {
if (singleFile != null) {
const formData = new FormData();
formData.append("lead_tag_number", "NAS00001");
formData.append("upload_pan_card_file", singleFile.singleFile.replace('file:/','file://'))
console.log(formData._parts[1][1])
fetch('https://xyz.tech/Android_API_CI/up_data',
{
method: 'post',
// body: JSON.stringify([{formData}]),
body : formData._parts[1][1],
headers: {
'Content-Type': 'multipart/form-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});
console.log(singleFile.singleFile.replace('file:/','file://'))
};
我收到这样的服务器响应
here------------1<pre>files dataArray
(
// I want My Image Here //
)
here you are
请帮忙
解决方案
推荐阅读
- android - 如何删除文件 API 30
- tableau-api - 如何在 tableau 中使用 mann whitney u 检验确定统计显着性
- javascript - 太多的重新渲染。React 限制了渲染的数量?Socket.io 聊天应用
- python - 如何从包含嵌套字典的字典创建 Pandas 数据框?
- html - 没有任何风格的形式
- awk - 如何使用 awk 格式化程序的输出,转换第一列但保持其余部分不变?
- deployment - 部署到 Azure 应用服务时出现 Azure Key Vault 依赖项错误
- java - 使用构造函数计算两点之间的欧几里得距离
- scala - Scala - 未来的“内存不足”
- java - Hibernate loader 在 System.identityHashCode 中花费大量时间