2

I know there are thousands of questions like this, but none of the solutions works for me:

  1. Change to Fetch Api
  2. Use format {uri: ..., type: ..., name: ...} in formData

I also have noticed that I can't send the formData directly in the "data" axios's property (when using Axios({...})), because the formData object has a property call "._parts", so I have to do:

let formData = new FormData()
formData('image', {uri: imagePicker.uri, name: 'some_name.jpeg', type: 'image/jpeg'})
formData('data', {name: 'Andrea'})

let xmlHttp = await Axios({
               method: 'POST',
               url: `url...`,
               data: formData._parts,
               headers: {
                 Authorization: `Bearer ${_token}`,
                'Content-Type': 'multipart/form-data',
               },
              } ).catch(error => {
                  throw error
              });

Then, in Node, I get this:

 req.body    -> [Object: null prototype] {}
 req.file    ->  undefined

upload.single("image"), in router.post and multerS3.

Some idea? Thank you

1 Answers1

1

I had the same problem with Axios for 6 days :D , there is no problem with Multer i got. but in the code you leave data should be formData not the formData._parts. just check it if it doesnt solve your problem i strongly recommend you to use https://github.com/joltup/rn-fetch-blob ,because the Axios package has got some issues you can also check it from github issue. for me Using the RNFetchBlob did the job i hope it helped

Amir Doreh
  • 1,369
  • 1
  • 13
  • 25