Can I send excel file and raw json in request body in single request to api?

38 Views Asked by At

Can I send excel file and raw json in request body in single request to api from postman?

1

There are 1 best solutions below

2
On

You can use FormData

const exampleData = {
 name: 'test'
};
const bodyFormData= new FormData();
bodyFormData.append('file', <FILE>)
bodyFormData.append('jsonData', JSON.stringify(exampleData))

axios({
  method: "post",
  URL: <URL>,
  data: bodyFormData,
  headers: { "Content-Type": "multipart/form-data" },
})
  • Get this request in a server
  • use some middleware
  • in the middleware you can split the file and jsonData for the following steps