javascriptnode.jsaxiosgetform-data

AxiosError 500 when uploading using .get in an ocr api


When I try to hit this API

const response = await api.get(
  `/upload/file?fileName=${file.name}&fileType=${
    file.type.split('/')[1]
  }&ocr=true&resource=presc`,
  {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: formData,
  }
);

I get this upload error:

HeroSection.tsx:96 Upload error: 
AxiosError {message: 'Request failed with status code 500', name: 'AxiosError',
code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …}', 

It works fine in Postman, I just have to pass formdata with key file and upload a file.


Solution

  • Since you're uploading a file, use api.post() instead of get.