我正在react-native-ios中实现文件上传, 这是我在react-native js上的代码:
const formData = new FormData();
formData.append('photo', { uri: image.sourceURL, name: image.filename, type: 'image/jpeg' });
// here is my formdata console :{uri: "file:///Users/.../DCIM/100APPLE/IMG_0002.JPG", name: "IMG_0002.JPG", type: "image/jpeg"}
fetch('services.php?action=MultiplefileUpload',{
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
'Accept': 'application/json'
},
body: formData
}).then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
})
.catch((error) => {
console.error(error);
});
在php页面上我写道:return $_FILES
回复是:photo: {name: "IMG_0002.JPG", type: "", tmp_name: "", error: 1, size: 0}
我的代码在哪里做错了?我也阅读了这个链接:Upload image file to php server from react-native