I am using Axios for API calls. I want to upload an image from mobile to the server. API is accepting data in binary form image. It is working fine from POSTMAN. But I cannot understand how to pass images in Axios in code.

This is the API curl from Postman.

curl --location --request PATCH 'https://development.wetraq.ca/v1/device/image' 
--header 'accept: application/json' 
--header 'Content-Type: image/jpeg' 
--header 'Authorization: Basic MTIwODU4MTM3MTk6Z2tNUWpRVWM=' 
--data '@'

Postman sample api calling.

  try {
  
      // Make the API request
      await request({
        url: 'device/image',
        data: imageData[0].base64, // here what I need to pass exactly.
        method: 'PATCH',
        config: {
          headers: {
            'Content-Type': 'image/jpeg',
            accept: 'application/json',
            maxContentLength: 100000000,
          },
          maxBodyLength: Infinity,
          maxContentLength: Infinity,
          responseType: 'json',
        },
      })
        .then(async (res: ApiResponse<any>) => {
          console.log('res ::: ', res.data);
          // Handle the response as needed
        })
        .catch((e: any) => {
          console.error('Oops :: ', e);
          // Handle the error as needed
          toast.show({
            type: 'error',
            message: e.message || 'Something went wrong',
            position: 'top',
          });
        });
    } catch (error) {
      console.warn('error ::: ', error);
      // Respond with a 500 Internal Server Error if something goes wrong
      return;
    }

this is the file data I get.

{"fileName": "1854487B-07A2-4BFA-9B64-B047202F8877.jpg", "fileSize": 2567402, "height": 2848, "type": "image/jpg", "uri": "file:///Users/theonetech/Library/Developer/CoreSimulator/Devices/FEC6EBCC-8A7E-4D43-B5E7-F5EB9F512EBF/data/Containers/Data/Application/A2FFD8E2-C3EE-45B0-A811-5467E27A761E/tmp/1854487B-07A2-4BFA-9B64-B047202F8877.jpg", "width": 4288}

I found one resource on the internet. https://medium.com/@j.lilian/how-to-use-axios-to-send-binary-data-579c3334ba72

But not able to understand.

New contributor

Aditya Patel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.