File Uploading in react native to php server

2019-06-06 04:19发布

问题:

I am implementing file uploading in react-native-ios, Here is my code on 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);
  });

And on php page I wrote:return $_FILES Response coming is : photo: {name: "IMG_0002.JPG", type: "", tmp_name: "", error: 1, size: 0}

Where am I doing wrong here in my code? I read this link as well: Upload image file to php server from react-native