Tuấn Vũ Quý
Tuấn Vũ Quý

Reputation: 57

React-Native, axios Post FormData with a different Content-Type of each parts

I have an api to upload some documents, I create a FormDdata variable with 2 keys: documentInfo (an object contain user info) and files(contain document info. I try with Postman and it success with content-type of documentInfo property is 'application/json', but i can not do it on my code

1

const formdata = new FormData()
formdata.append('documentInfo', documentInfo)
formdata.append('files', file)

{
    "method": "POST",
    "data": formdata,
    "timeout": 30000,
    "headers": {
        "Content-Type": "multipart/form-data",
    },
    "url": "url"
}

Upvotes: 2

Views: 653

Answers (1)

YourNeighbor
YourNeighbor

Reputation: 88

You need to pass file param correctly. It's a bit different from Postman

formData.append('files', {
    uri: file.uri,
    type: file.type,
    name: `abc.png`,
  })

Upvotes: 2

Related Questions