-1

In my react app project I am sending a formdata post by axios to a local web api service on .net core 6. The formData has a file and a folder name appended properties but the request to the service returns : AxiosError: Request failed with status code 400 [1] at settle (file:///D:/Documents/React/psarchetypeeditor/node_modules/axios/lib/core/settle.js:19:12) [1] at IncomingMessage.handleStreamEnd (file:///D:/Documents/React/psarchetypeeditor/node_modules/axios/lib/adapters/http.js:570:11) [1] at IncomingMessage.emit (node:events:525:35) [1] at endReadableNT (node:internal/streams/readable:1359:12) [1] at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { [1] code: 'ERR_BAD_REQUEST', this is my post code :

  const formData = new FormData();
  formData.append('folder', folder);
  formData.append('file', file);
  
  console.log("formData")
await axios.post('https://localhost:7275/Upload', formData, {
    headers: {
      "Content-Type": 'multipart/form-data'
    },
    withCredentials: true,
    httpsAgent: new https.Agent({rejectUnauthorized: false,}),
  }).then((response) => {
    console.log("Response Data :       " + response.data);
    res.json(response.data);
  }).catch ((error) => {
    console.error('Upload proxy error:    ', error);
    return res.status(500).send('Upload proxy error');  
  })
})

What would be the problem and how should exactly be the service to get this type of information?

saeed
  • 1
  • 1
  • 1
    Does this answer your question? [400 BAD request HTTP error code meaning?](https://stackoverflow.com/questions/19671317/400-bad-request-http-error-code-meaning) – Quentin Aug 23 '23 at 09:00
  • could you show the controller of your webapi? – Ruikai Feng Aug 24 '23 at 01:20

1 Answers1

0

I found the answer. The problem was that while I receive the file data in the proxy server by express fileupload middleware I need to change the file.data to Blob and then I can send it by axios as formdata to the api service and it works.

saeed
  • 1
  • 1