Search code examples
node.jsreact-nativemulterform-data

FormData throws Network Error All the time


I am trying to upload a file to my NodeJs Server from My Mobile ReactNative App.

I tried to use FormData with Axios post but it is resulting in a NetworkError. Logging the FormData object before sending it gives me an object with an Array _parts that contains Arrays of my fields.

Also when I console.log the prototypes of FormData I only get two methods that I can use, which are append and getParts. I can't use any method that does exist in the documentation like getHeaders or getBoundary

Now If I want to make a file upload without using FormData, Should I send a fileStream of the picture I want to upload or just send the uri of the picture? I am using multer to capture the Files in my server.


Solution

  • What was causing the Network Error is me using a nested object inside dataForm.

    //Other code onTop
    const {location, ...other} = payload;
    form.append("location", JSON.stringify(location));
    ...
    

    I hope this might help someone.

    Also Files Are Blobs, basically a readabaleStream. Read More About it Here