Skip to content
Advertisement

How to upload files from react native app to PHP server?

I developed a PHP project, now I am working on connecting it to react native app. However, I tried many codes to upload image to the server nothing works.

Here is my code example,

JavaScript

};

And for the PHP server side (upload.php), here is the code

JavaScript

I got this code from here https://aboutreact.com/file-uploading-in-react-native/

And I am getting

this error

Can anyone help me? Any alternative solution will be fine.

Edit:

based on @Sadia Chaudhary code this function works

JavaScript

};

Advertisement

Answer

The error has nothing to do with the image upload. You are facing this error because of response.json(). Also, try to convert image like this.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement